Skip to content
Michael Miller edited this page Jul 27, 2023 · 2 revisions

RtcPCF8563 object provides access to all the functions of the PCF8563 module. Along with date and time, this also includes setting alarms/timers, and defining the square wave pin function.

Constructors

template<class T_WIRE_METHOD> RtcPCF8563(T_WIRE_METHOD& wire)

Construct a Rtc object using the provided WIRE method.
T_WIRE_METHOD - the typename of the class to use for the wire method. TwoWire is the normal hardware method class.
wire - the instance of the T_WIRE_METHOD to use. Wire is the normal hardware instance to use.
Below is an example of how to create an instance of the object using the normal Arduino hardware Wire support.

#include <Wire.h> 
#include <RtcPCF8563.h>

RtcPCF8563<TwoWire> Rtc(Wire);

If you want to use SoftwareWire library, you can replace the above with this and it will work.

#include <SoftwareWire.h> 
#include <RtcPCF8563.h>

SoftwareWire myWire(SDA, SCL); // replace with the pins you use
RtcPCF8563<SoftwareWire> Rtc(myWire);

Methods

void Begin()

The normal begin method that should be called within Setup()

uint8_t LastError()

<return>, the error code from the last Wire transaction. After each method call below, you may check if this return value for an error. See https://www.arduino.cc/en/Reference/WireEndTransmission for values of this error.

bool IsDateTimeValid()

<return>, the RTC has confidence in the date and time it returns. If this returns false it usually means the battery is dead or the date and time has never been set.

bool GetIsRunning()

<return>, the actual clock is running on the RTC.

void SetIsRunning(bool isRunning)

isRunning - set if the clock is running. If false then the time value will not progress.

void SetDateTime(const RtcDateTime& dt)

dt - the date and time to set the RTC to.

RtcDateTime GetDateTime()

<return>, the current date and time in the RTC.

void SetSquareWavePin(PCF8563SquareWavePinMode pinMode)

piMode - the frequency to have the SquareWave pin pulse as. One of the following values:

  • PCF8563SquareWavePinMode_None - disable the pin
  • PCF8563SquareWavePinMode_32kHz - 32768 times per second
  • PCF8563SquareWavePinMode_1kHz - 1024 times per second
  • PCF8563SquareWavePinMode_32Hz - 32 times a second
  • PCF8563SquareWavePinMode_1Hz - one per second

void SetAlarm(const PCF8563Alarm& alarm)

Set an alarm that is accurate to the minute with various modes. Repeats at the matching time elements. Will pulse the INT pin when alarm triggers.
alarm - a structure that defines all the properties to set the alarm.

void StopAlarm()

Stops the alarm function.

void SetTimer(PCF8563TimerMode mode, uint8_t time)

Sets a timer that triggers on the given time elements. Repeats using the given time. Will pulse the INT pin when timer triggers.
mode - a enum that defines the time magnitude that the time arguments represents.

  • PCF8563TimerMode_4096thOfASecond - 1/4096th of a second
  • PCF8563TimerMode_64thOfASecond - 1/64th of a second
  • PCF8563TimerMode_Seconds - seconds
  • PCF8563TimerMode_Minutes - minutes, triggers at the top of the minute

time - (0-255) the number of time elements defined by mode to count down with

Example of setting a timer for every 60 seconds starting when you make this call:

rtc.SetTimer(PCF8563TimerMode_Seconds, 60);

Example of setting a timer for the top of every minute:

rtc.SetTimer(PCF8563TimerMode_Minutes, 1);

void StopTimer()

Stops the timer function.

bool LatchAlarmTriggeredFlag()

This method must be called after an alarm is triggered otherwise it will not trigger again. It is used as a means to confirm you handled the alarm.
<return>, true if the alarm was active when this method is called.

bool LatchTimerTriggeredFlag()

This method must be called after a timer is triggered otherwise it will not trigger again. It is used as a means to confirm you handled the timer.
<return>, true if the timer was active when this method is called.

bool GetAlarmTriggered()

Tests the status of the alarm.
<return>, true if the alarm was active when this method is called.

bool GetTimerTriggered()

Tests the status of the timer.
<return>, true if the timer was active when this method is called.