ArduinoLibs
|
Communicates with a DS3232 realtime clock chip via I2C. More...
#include <DS3232RTC.h>
Public Member Functions | |
DS3232RTC (I2CMaster &bus, uint8_t oneHzPin=255) | |
Attaches to a realtime clock slave device on bus. More... | |
bool | isRealTime () const |
Returns true if the realtime clock is on the I2C bus; false if the time and date are simulated. | |
bool | hasUpdates () |
Returns true if the realtime clock has updated since the last call to this function. More... | |
void | readTime (RTCTime *value) |
Reads the current time from the realtime clock into value. More... | |
void | readDate (RTCDate *value) |
Reads the current date from the realtime clock into value. More... | |
void | writeTime (const RTCTime *value) |
Updates the time in the realtime clock to match value. More... | |
void | writeDate (const RTCDate *value) |
Updates the date in the realtime clock to match value. More... | |
void | readAlarm (uint8_t alarmNum, RTCAlarm *value) |
Reads the details of the alarm with index alarmNum into value. More... | |
void | writeAlarm (uint8_t alarmNum, const RTCAlarm *value) |
Updates the details of the alarm with index alarmNum from value. More... | |
int | byteCount () const |
Returns the number of bytes of non-volatile memory that can be used for storage of arbitrary settings, excluding storage used by alarms. More... | |
uint8_t | readByte (uint8_t offset) |
Reads the byte at offset within the realtime clock's non-volatile memory. More... | |
void | writeByte (uint8_t offset, uint8_t value) |
Writes value to offset within the realtime clock's non-volatile memory. More... | |
int | readTemperature () |
Reads the value of the temperature sensor and returns the temperature in quarters of a degree celcius. More... | |
void | enableAlarmInterrupts () |
Enables the generation of interrupts for alarms 0 and 1. More... | |
void | disableAlarmInterrupts () |
Disables the generation of interrupts for alarms 0 and 1. More... | |
int | firedAlarm () |
Determines which of alarms 0 or 1 have fired since the last call. More... | |
void | enable32kHzOutput () |
Enables the 32 kHz output on the DS3232 chip. More... | |
void | disable32kHzOutput () |
Disables the 32 kHz output on the DS3232 chip. More... | |
Public Member Functions inherited from RTC | |
RTC () | |
Constructs a new realtime clock handler. More... | |
Additional Inherited Members | |
Public Types inherited from RTC | |
enum | DayOfWeek { Monday = 1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } |
Day of the week corresponding to a date. More... | |
Static Public Member Functions inherited from RTC | |
static void | adjustDays (RTCDate *date, uint8_t flags) |
Adjusts date up or down one day according to flags. More... | |
static void | adjustMonths (RTCDate *date, uint8_t flags) |
Adjusts date up or down one month according to flags. More... | |
static void | adjustYears (RTCDate *date, uint8_t flags) |
Adjusts date up or down one year according to flags. More... | |
static DayOfWeek | dayOfWeek (const RTCDate *date) |
Returns the day of the week corresponding to date. More... | |
Static Public Attributes inherited from RTC | |
static const uint8_t | ALARM_COUNT = 4 |
Number of alarms that are supported by RTC::readAlarm() and RTC::writeAlarm(). | |
static const int | NO_TEMPERATURE = 32767 |
Value that is returned from readTemperature() if the realtime clock chip cannot determine the temperature. | |
static const uint8_t | INCREMENT = 0x0000 |
Increment the day, month, or year in a call to adjustDays(), adjustMonths(), or adjustYears(). | |
static const uint8_t | DECREMENT = 0x0001 |
Decrement the day, month, or year in a call to adjustDays(), adjustMonths(), or adjustYears(). | |
static const uint8_t | WRAP = 0x0002 |
Wrap around to the beginning of the current month/year rather than advance to the next one. | |
Communicates with a DS3232 realtime clock chip via I2C.
This class simplifies the process of reading and writing the time and date information in a DS3232 realtime clock chip. The class also provides support for reading and writing information about alarms and other clock settings.
If there is no DS3232 chip on the I2C bus, this class will fall back to the RTC class to simulate the current time and date based on the value of millis().
Alarms 0 and 1 can be set to generate an interrupt when they fire using enableAlarmInterrupts(). The firedAlarm() function can be used to determine which alarm has fired. Alarms 2 and 3 cannot be monitored with interrupts.
The DS3232 uses a 2-digit year so this class is limited to dates between 2000 and 2099 inclusive.
Note: if this class has not been used with the DS3232 chip before, then the contents of NVRAM will be cleared. Any previous contents will be lost.
Definition at line 30 of file DS3232RTC.h.
DS3232RTC::DS3232RTC | ( | I2CMaster & | bus, |
uint8_t | oneHzPin = 255 |
||
) |
Attaches to a realtime clock slave device on bus.
If oneHzPin is not 255, then it indicates a digital input pin that is connected to the 1 Hz square wave output on the realtime clock. This input is used by hasUpdates() to determine if the time information has changed in a non-trivial manner.
If you wish to use enableAlarmInterrupts(), then oneHzPin must be 255.
Definition at line 126 of file DS3232RTC.cpp.
|
virtual |
Returns the number of bytes of non-volatile memory that can be used for storage of arbitrary settings, excluding storage used by alarms.
Reimplemented from RTC.
Definition at line 335 of file DS3232RTC.cpp.
void DS3232RTC::disable32kHzOutput | ( | ) |
Disables the 32 kHz output on the DS3232 chip.
Definition at line 458 of file DS3232RTC.cpp.
void DS3232RTC::disableAlarmInterrupts | ( | ) |
Disables the generation of interrupts for alarms 0 and 1.
Definition at line 393 of file DS3232RTC.cpp.
void DS3232RTC::enable32kHzOutput | ( | ) |
Enables the 32 kHz output on the DS3232 chip.
Definition at line 444 of file DS3232RTC.cpp.
void DS3232RTC::enableAlarmInterrupts | ( | ) |
Enables the generation of interrupts for alarms 0 and 1.
When the interrupt occurs, use firedAlarm() to determine which alarm has fired. The application is responsible for implementing the interrupt service routine to watch for the interrupt.
Note: this function does nothing if the 1 Hz pin was enabled in the constructor, but firedAlarm() can still be used to determine which alarm has fired when hasUpdates() reports that there is an update available.
Definition at line 380 of file DS3232RTC.cpp.
int DS3232RTC::firedAlarm | ( | ) |
Determines which of alarms 0 or 1 have fired since the last call.
Returns 0 if alarm 0 has fired, 1 if alarm 1 has fired, 2 if both alarms have fired, or -1 if neither alarm has fired.
The fired alarm state will be cleared, ready for the next call.
This function cannot be used to determine if alarms 2 or 3 have fired as they are stored in NVRAM and are not handled specially by the DS3232.
Definition at line 416 of file DS3232RTC.cpp.
|
virtual |
Returns true if the realtime clock has updated since the last call to this function.
The default implementation returns true, indicating that an update is always available to be read.
Reimplemented from RTC.
Definition at line 166 of file DS3232RTC.cpp.
|
virtual |
Reads the details of the alarm with index alarmNum into value.
The alarmNum parameter must be between 0 and ALARM_COUNT - 1.
Alarm details are stored at the end of the realtime clock's non-volatile memory.
Reimplemented from RTC.
Definition at line 278 of file DS3232RTC.cpp.
|
virtual |
Reads the byte at offset within the realtime clock's non-volatile memory.
The offset parameter must be between 0 and byteCount() - 1.
Reimplemented from RTC.
Definition at line 340 of file DS3232RTC.cpp.
|
virtual |
Reads the current date from the realtime clock into value.
The time should be read first with readTime() as the default implementation only advances the date when the time is read and it crosses midnight.
Reimplemented from RTC.
Definition at line 225 of file DS3232RTC.cpp.
|
virtual |
Reads the value of the temperature sensor and returns the temperature in quarters of a degree celcius.
Returns the value NO_TEMPERATURE if the realtime clock chip cannot determine the temperature.
Reimplemented from RTC.
Definition at line 356 of file DS3232RTC.cpp.
|
virtual |
Reads the current time from the realtime clock into value.
Reimplemented from RTC.
Definition at line 205 of file DS3232RTC.cpp.
|
virtual |
Updates the details of the alarm with index alarmNum from value.
The alarmNum parameter must be between 0 and ALARM_COUNT - 1.
Alarm details are stored at the end of the realtime clock's non-volatile memory.
Reimplemented from RTC.
Definition at line 298 of file DS3232RTC.cpp.
|
virtual |
Writes value to offset within the realtime clock's non-volatile memory.
The offset parameter must be between 0 and byteCount() - 1.
Reimplemented from RTC.
Definition at line 348 of file DS3232RTC.cpp.
|
virtual |
Updates the date in the realtime clock to match value.
Reimplemented from RTC.
Definition at line 264 of file DS3232RTC.cpp.
|
virtual |
Updates the time in the realtime clock to match value.
Reimplemented from RTC.
Definition at line 250 of file DS3232RTC.cpp.