![]() |
MD_DS3231 Real Time Clock Library
1.3
Library to control DS3231 high precision clock with alarms
|
The library has a simple interface to the RTC hardware implemented through:
Alarms may be operated in either polled mode or interrupt mode, as described below.
The control() and status() methods are the main interface to action setting parameters or status values. The parameters used for each are similar, but not symmetrical, due to the way the hardware is implemented. The table below highlights the combinations of valid parameters for the control() method and whether a parameter can be changed by user code.
The status() method will return the current value from the parameter nominated and is guaranteed to be in the valid set.
Function | R | W | Write value ------------------— |
---|---|---|---|
DS3231_CLOCK_HALT | Y | Y | DS3231_ON, DS3231_OFF |
DS3231_SQW_ENABLE | Y | Y | DS3231_ON, DS3231_OFF |
DS3231_SQW_TYPE | Y | Y | DS3231_SQW_1HZ, DS3231_SQW_1KHZ, DS3231_SQW_4KHZ, DS3231_SQW_8KHZ |
DS3231_12H | Y | Y | DS3231_ON, DS3231_OFF |
DS3231_TCONV | Y | Y | DS3231_ON, DS3231_OFF |
DS3231_INT_ENABLE | Y | Y | DS3231_ON, DS3231_OFF |
DS3231_A1_INT_ENABLE | Y | Y | DS3231_ON, DS3231_OFF |
DS3231_A2_INT_ENABLE | Y | Y | DS3231_ON, DS3231_OFF |
DS3231_HALTED_FLAG | Y | Y | DS3231_OFF |
DS3231_32KHZ_ENABLE | Y | Y | DS3231_ON, DS3231_OFF |
DS3231_BUSY_FLAG | Y | N | N/A |
DS3231_A1_FLAG | Y | Y | DS3231_OFF |
DS3231_A2_FLAG | Y | Y | DS3231_OFF |
DS3231_AGING_OFFSET | Y | Y | 0x00 - 0xff |
Reading the current time from the clock is a call to the readTime() method. The current date and time is then available in the interface registers.
Writing the current time is a sequence of writing to the interface registers followed by a call to the writeTime() method.
Writing the alarm trigger time data is achieve by writing to the interface registers followed by a call to the setAlarm1() or setAlarm2() method. The alarm type is specified when the method is invoked, and is one of the almType_t values, noting that values are specific to alarm 1 and alarm 2.
Reading the alarm trigger set is by invoking the getAlarm1() or getAlarm2() methods to load the interface registers, from which the data can be read. The alarm trigger type is obtained separately using the getAlarm1Type() or getAlarm2Type() methods.
Checking if an alarm has triggered can be done in two ways, depending on whether it is a polled alarm or interrupts have been enabled.
The DS3231_LCD_Time example has examples of the different ways of interacting with the RTC.