Skip to content
Josh Perriman edited this page Aug 23, 2018 · 3 revisions

Overview

This library is used to communicate with the PCF2123 RTC. It can be used to set and retrieve the time. It can be included by adding the following include statement at the top of your Arduino sketch.

#include <PCF2123.h>

More features need to be added to this library in order to access the more advanced features of this RTC. Features like the Alarm function with interrupt output.


Time struct

struct Time{
	uint8_t Second;
	uint8_t Minute;
	uint8_t Hour;
	uint8_t Day;
	uint8_t Wday;
	uint8_t Month;
	uint8_t Year;
};

The time structure is used to set the time or is returned if the current time is requested.


PCF2123

PCF2123(uint8_t ss_);

This needs to be called first to create an instance of the RTC class.

Args
  • ss_ = Pin that the RTC, SPI slave select is connected to

begin

void begin();

This needs to be called before any other functions. Its used to setup the create pins as inputs, outputs and to initialise the SPI used by the RTC chip.

get_time

void get_time(Time *t);
Args
  • t = A pointer to a Time struct where the current time will be stored
Example
PCF2123 time(A5);
time.begin();

Time t;
time.get_time(&t);

The struct t now contains the current date time information.


set_time

Used to set the time stored on the RTC. A Time struct needs to be created and the time in it set to the correct value. This struct needs to then be passed to the function which will then set the time.

void set_time(Time new_time);
Args
  • new_time = A time struct containing the current time set by the user
Example

There is an example with the library called "Set_time". This allows the user to send the time over serial to the node and it will set the time in the RTC. See the example for for details

Clone this wiki locally