MD_DS3231 Real Time Clock Library  1.3
Library to control DS3231 high precision clock with alarms
MD_DS3231 Class Reference

#include <MD_DS3231.h>

Public Member Functions

 MD_DS3231 ()
 
 MD_DS3231 (int sda, int scl)
 
Methods for object and hardware control.
boolean control (codeRequest_t item, uint8_t value)
 
codeStatus_t status (codeRequest_t item)
 
Methods for RTC operations
boolean readTime (void)
 
boolean writeTime (void)
 
boolean setCentury (uint8_t c)
 
uint8_t getCentury (void)
 
void now (void)
 
boolean isRunning (void)
 
Methods for Alarm 1 operations
boolean readAlarm1 (void)
 
boolean writeAlarm1 (almType_t almType)
 
boolean setAlarm1Type (almType_t almType)
 
almType_t getAlarm1Type (void)
 
boolean checkAlarm1 (void)
 
boolean setAlarm1Callback (void(*cb)(void))
 
Methods for Alarm 2 operations
boolean readAlarm2 (void)
 
boolean writeAlarm2 (almType_t almType)
 
boolean setAlarm2Type (almType_t almType)
 
almType_t getAlarm2Type (void)
 
boolean checkAlarm2 (void)
 
boolean setAlarm2Callback (void(*cb)(void))
 
Miscellaneous methods
uint8_t readRAM (uint8_t addr, uint8_t *buf, uint8_t len)
 
uint8_t writeRAM (uint8_t addr, uint8_t *buf, uint8_t len)
 
uint8_t calcDoW (uint16_t yyyy, uint8_t mm, uint8_t dd)
 
float readTempRegister (void)
 

Public Attributes

Public variables for reading and writing time data
uint16_t yyyy
 Year including the millennium and century. See setCentury() for more information.
 
uint8_t mm
 Month (1-12)
 
uint8_t dd
 Date of the month (1-31)
 
uint8_t h
 Hour of the day (1-12) or (0-23) depending on the am/pm or 24h mode setting.
 
uint8_t m
 Minutes past the hour (0-59)
 
uint8_t s
 Seconds past the minute (0-59)
 
uint8_t dow
 Day of the week (1-7). Sequential number; day coding depends on the application and zero is an undefined value.
 
uint8_t pm
 Non-zero if 12 hour clock mode and PM, always zero for 24 hour clock. Check the time and if < 12 then check this indicator.
 

Detailed Description

Core object for the MD_DS3231 library

Constructor & Destructor Documentation

◆ MD_DS3231() [1/2]

MD_DS3231::MD_DS3231 ( )

Class Constructor

Instantiate a new instance of the class. One instance of the class is created in the libraries as the RTC object.

◆ MD_DS3231() [2/2]

MD_DS3231::MD_DS3231 ( int  sda,
int  scl 
)

Overloaded Class Constructor (ESP8266 only)

Provides a way to assign custom SCL and SDA pins if the architecture supports them.

Parameters
sdaPin number for the SDA signal
sclPin number for the SCL signal

Member Function Documentation

◆ calcDoW()

uint8_t MD_DS3231::calcDoW ( uint16_t  yyyy,
uint8_t  mm,
uint8_t  dd 
)

Calculate day of week for a given date

Given the specified date, calculate the day of week.

See also
Wikipedia https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week
Parameters
yyyyyear for specified date. yyyy must be > 1752.
mmmonth for the specified date where mm is in the range [1..12], 1 = January.
dddate for the specified date in the range [1..31], where 1 = first day of the month.
Returns
dow value calculated [1..7], where 1 = Sunday.

◆ checkAlarm1()

boolean MD_DS3231::checkAlarm1 ( void  )

Check if Alarm 1 has triggered

The method checks if the alarm triggered flag has been set. If it has the callback function is invoked. In either case the triggered flag is reset.

See also
setAlarm1Callback() method.
Returns
true if the alarm triggered, false otherwise.

◆ checkAlarm2()

boolean MD_DS3231::checkAlarm2 ( void  )

Check if Alarm 2 has triggered

The method checks if the alarm triggered flag has been set. If it has the callback function is invoked. In either case the triggered flag is reset.

See also
setAlarm2Callback() method.
Returns
true if the alarm triggered, false otherwise.

◆ control()

boolean MD_DS3231::control ( codeRequest_t  item,
uint8_t  value 
)

Set the control status of the specified parameter to the specified value.

The device has a number of control parameters that can be set through this method. The type of control action required is passed through the mode parameter and should be one of the control actions defined by codeRequest_t. The value that needs to be supplied on the control action required is one of the defined actions in codeStatus_t or a numeric parameter suitable for the control action. Not all combinations of item and value are valid.

See also
Software Overview section in the introduction for a table of valid combinations.
Parameters
itemone of the codeRequest_t values.
valueone codeStatus_t values.
Returns
false if parameter errors, true otherwise.

◆ getAlarm1Type()

almType_t MD_DS3231::getAlarm1Type ( void  )

Get the Alarm 1 trigger type

Read the alarm trigger from the RTC. This will be one of the values in almType_t, noting that not all values are valid for each alarm.

See also
setAlarm1Type() method
Returns
almType_t current setting for the alarm or ALM_ERROR if error

◆ getAlarm2Type()

almType_t MD_DS3231::getAlarm2Type ( void  )

Get the Alarm 2 trigger type

Read the alarm trigger from the RTC. This will be one of the values in almType_t, noting that not all values are valid for each alarm.

See also
setAlarm2Type() method
Returns
almType_t current setting for the alarm or ALM_ERROR if error

◆ getCentury()

uint8_t MD_DS3231::getCentury ( void  )

Get the current century for year handling in the library

Return the current century library setting.

See also
getCentury() method for an explanation of year handling
Returns
the year base century.

◆ isRunning()

boolean MD_DS3231::isRunning ( void  )

Compatibility function - Check if RTC is running

Wrapper for a HALT status check

See also
status() method
Returns
true if running, false otherwise.

◆ now()

void MD_DS3231::now ( void  )

Compatibility function - Read the current time

Wrapper to read the current time.

See also
readTime() method
Returns
no return value.

◆ readAlarm1()

boolean MD_DS3231::readAlarm1 ( void  )

Read the current Alarm 1 time into the interface registers

Query the RTC for the current alarm 1 trigger time and load it into the library interface registers (dd, h, m, s, dow, pm) from which the data can be accessed.

See also
readAlarm1() method
Returns
false if errors, true otherwise.

◆ readAlarm2()

boolean MD_DS3231::readAlarm2 ( void  )

Read the current Alarm 2 time into the interface registers

Query the RTC for the current alarm 2 trigger time and load it into the library interface registers (dd, h, m, s, dow, pm) from which the data can be accessed.

See also
writeAlarm2() method
Returns
false if errors, true otherwise.

◆ readRAM()

uint8_t MD_DS3231::readRAM ( uint8_t  addr,
uint8_t *  buf,
uint8_t  len 
)

Read the raw RTC clock data

Read len bytes from the RTC clock starting at addr as raw data into the buffer supplied. The size of the buffer should be at least MAX_BUF bytes long (defined in the library cpp file).

See also
writeRAM() method
Parameters
addrstarting address for the read.
bufaddress of the receiving byte buffer.
lennumber of bytes to read.
Returns
number of bytes successfully read.

◆ readTempRegister()

float MD_DS3231::readTempRegister ( void  )

Read the temperature register in the RTC

Read the temperature compensation register in the RTC in degrees C. Resolution is to 0.25 degrees C on the fractional part.

Returns
the temperature in degrees C.

◆ readTime()

boolean MD_DS3231::readTime ( void  )

Read the current time into the interface registers

Query the RTC for the current time and load that into the library interface registers (yyyy, mm, dd, h, m, s, dow, pm) from which the data can be accessed.

See also
setCentury() method.
Returns
false if errors, true otherwise.

◆ setAlarm1Callback()

boolean MD_DS3231::setAlarm1Callback ( void(*)(void)  cb)

Set the callback function for Alarm 1

Pass the address of the callback function to the libraries. The callback function prototype is

void functionName(void);

and is invoked when the checkAlarm1() method is invoked. Set to NULL (default) to disable this feature.

See also
setAlarm1Callback() method.
Parameters
cbthe address of the callback function.
Returns
false if errors, true otherwise.

◆ setAlarm1Type()

boolean MD_DS3231::setAlarm1Type ( almType_t  almType)

Set the Alarm 1 trigger type

Set the alarm trigger to one of the values in almType_t, noting that not all values are valid for each alarm.

See also
getAlarm1Type() method
Parameters
almTypethe type of alarm trigger required
Returns
false if errors, true otherwise.

◆ setAlarm2Callback()

boolean MD_DS3231::setAlarm2Callback ( void(*)(void)  cb)

Set the callback function for Alarm 2

Pass the address of the callback function to the libraries. The callback function prototype is

void functionName(void);

and is invoked when the checkAlarm2() method is invoked. Set to NULL (default) to disable this feature

See also
setAlarm2Callback() method.
Parameters
cbthe address of the callback function.
Returns
false if errors, true otherwise.

◆ setAlarm2Type()

boolean MD_DS3231::setAlarm2Type ( almType_t  almType)

Set the Alarm 2 trigger type

Set the alarm trigger to one of the values in almType_t, noting that not all values are valid for each alarm.

See also
getAlarm2Type() method
Parameters
almTypethe type of alarm trigger required
Returns
false if errors, true otherwise.

◆ setCentury()

boolean MD_DS3231::setCentury ( uint8_t  c)

Set the current century for year handling in the library

The RTC only stores the last 2 digits of the year and has a century indicator. This means in practice that dates in a range of 199 years from a base date can be represented by the library. This method allows user code to set a base century for date handling in the library. The default for this value in the libraries is 20, which allows dates in the range from 2000 (20*100) to 2199.

See also
getCentury() method
Parameters
cthe year base century. Dates will start from (c*100).
Returns
false if errors, true otherwise.

◆ status()

codeStatus_t MD_DS3231::status ( codeRequest_t  item)

Obtain the current setting for the specified parameter.

Any of the parameters that can be set from the control() method can be queried using this method. The codeStatus_t value returned will be one of the valid values for the control() method for each specific codeRequest_t parameter.

See also
Software Overview section in the introduction for a table of valid combinations.
Parameters
itemone of the codeRequest_t values.
Returns
codeStatus_t value setting or DS3231_ERROR if an error occurred.

◆ writeAlarm1()

boolean MD_DS3231::writeAlarm1 ( almType_t  almType)

Write the current Alarm 1 time from the interface registers

Write the data in the interface registers (dd, h, m, s, dow, pm) as the Alarm 1 trigger time in the RTC and set the alarm trigger to one of the values in almType_t, noting that not all values are valid for each alarm.

See also
writeAlarm1() method
Parameters
almTypethe type of alarm trigger required
Returns
false if errors, true otherwise.

◆ writeAlarm2()

boolean MD_DS3231::writeAlarm2 ( almType_t  almType)

Write the current Alarm 2 time from the interface registers

Write the data in the interface registers (dd, h, m, s, dow, pm) as the Alarm 2 trigger time in the RTC and set the alarm trigger to one of the values in almType_t, noting that not all values are valid for each alarm.

See also
readAlarm2() method
Parameters
almTypethe type of alarm trigger required
Returns
false if errors, true otherwise.

◆ writeRAM()

uint8_t MD_DS3231::writeRAM ( uint8_t  addr,
uint8_t *  buf,
uint8_t  len 
)

Write the raw RTC clock data

Write len bytes of data in the buffer supplied to the RTC clock starting at addr. The size of the buffer should be at least len bytes long.

See also
readRAM() method
Parameters
addrstarting address for the write.
bufaddress of the data buffer.
lennumber of bytes to write.
Returns
number of bytes successfully written.

◆ writeTime()

boolean MD_DS3231::writeTime ( void  )

Write the current time from the interface registers

Write the data in the interface registers (yyyy, mm, dd, h, m, s, dow, pm) as the current time in the RTC.

See also
setCentury() method.
Returns
false if errors, true otherwise.

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