ArduinoLibs
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | List of all members
DS3232RTC Class Reference

Communicates with a DS3232 realtime clock chip via I2C. More...

#include <DS3232RTC.h>

Inheritance diagram for DS3232RTC:
RTC

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.
 

Detailed Description

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.

See Also
RTC, DS1307RTC

Definition at line 30 of file DS3232RTC.h.

Constructor & Destructor Documentation

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.

See Also
hasUpdates(), enableAlarmInterrupts()

Definition at line 126 of file DS3232RTC.cpp.

Member Function Documentation

int DS3232RTC::byteCount ( ) const
virtual

Returns the number of bytes of non-volatile memory that can be used for storage of arbitrary settings, excluding storage used by alarms.

See Also
readByte(), writeByte()

Reimplemented from RTC.

Definition at line 335 of file DS3232RTC.cpp.

void DS3232RTC::disable32kHzOutput ( )

Disables the 32 kHz output on the DS3232 chip.

See Also
enable32kHzOutput()

Definition at line 458 of file DS3232RTC.cpp.

void DS3232RTC::disableAlarmInterrupts ( )

Disables the generation of interrupts for alarms 0 and 1.

See Also
enableAlarmInterrupts()

Definition at line 393 of file DS3232RTC.cpp.

void DS3232RTC::enable32kHzOutput ( )

Enables the 32 kHz output on the DS3232 chip.

See Also
disable32kHzOutput()

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.

See Also
disableAlarmInterrupts(), firedAlarm()

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.

See Also
enableAlarmInterrupts()

Definition at line 416 of file DS3232RTC.cpp.

bool DS3232RTC::hasUpdates ( )
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.

void DS3232RTC::readAlarm ( uint8_t  alarmNum,
RTCAlarm value 
)
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.

See Also
writeAlarm(), alarmCount()

Reimplemented from RTC.

Definition at line 278 of file DS3232RTC.cpp.

uint8_t DS3232RTC::readByte ( uint8_t  offset)
virtual

Reads the byte at offset within the realtime clock's non-volatile memory.

The offset parameter must be between 0 and byteCount() - 1.

See Also
writeByte(), byteCount()

Reimplemented from RTC.

Definition at line 340 of file DS3232RTC.cpp.

void DS3232RTC::readDate ( RTCDate value)
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.

See Also
writeDate(), readTime()

Reimplemented from RTC.

Definition at line 225 of file DS3232RTC.cpp.

int DS3232RTC::readTemperature ( )
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.

void DS3232RTC::readTime ( RTCTime value)
virtual

Reads the current time from the realtime clock into value.

See Also
writeTime(), readDate()

Reimplemented from RTC.

Definition at line 205 of file DS3232RTC.cpp.

void DS3232RTC::writeAlarm ( uint8_t  alarmNum,
const RTCAlarm value 
)
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.

See Also
readAlarm(), alarmCount()

Reimplemented from RTC.

Definition at line 298 of file DS3232RTC.cpp.

void DS3232RTC::writeByte ( uint8_t  offset,
uint8_t  value 
)
virtual

Writes value to offset within the realtime clock's non-volatile memory.

The offset parameter must be between 0 and byteCount() - 1.

See Also
readByte(), byteCount()

Reimplemented from RTC.

Definition at line 348 of file DS3232RTC.cpp.

void DS3232RTC::writeDate ( const RTCDate value)
virtual

Updates the date in the realtime clock to match value.

See Also
readDate(), writeTime()

Reimplemented from RTC.

Definition at line 264 of file DS3232RTC.cpp.

void DS3232RTC::writeTime ( const RTCTime value)
virtual

Updates the time in the realtime clock to match value.

See Also
readTime(), writeDate()

Reimplemented from RTC.

Definition at line 250 of file DS3232RTC.cpp.


The documentation for this class was generated from the following files: