Class DS3231M
Class for DS3231M RTC communication.
#include <DS3231M.h>
Public Attributes
| Type | Name |
|---|---|
| uint8_t | rtc Array to store RTC time and date data. |
Public Functions
| Type | Name |
|---|---|
| DS3231M (TwoWire * pWire=&Wire) Constructor of the DS3231M class. |
|
| bool | begin (void) Initializes I2C communication. |
| void | clearAlarm () Clears the alarm flags in the status register. |
| void | disable32k () Disables the 32kHz square wave output on the SQW/INT pin. |
| void | enable32k () Enables the 32kHz square wave output on the SQW/INT pin. |
| DateTime | getRTCTime () Gets the current RTC time. |
| float | getTemp () Gets the current temperature from the DS3231M sensor. |
| bool | isAlarm () Checks if any alarm has been triggered. |
| bool | lostPower (void) Checks if the RTC lost backup power. |
| void | setAlarm1 (const DateTime & dt, eAlarmType_t type) Sets the first RTC alarm (alarm 1). |
| void | setAlarm2 (const DateTime & dt, eAlarmType_t type) Sets the second RTC alarm (alarm 2). |
| void | setRTCTime (uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) Sets the RTC time and date. |
| ~DS3231M () Destructor of the DS3231M class. |
Protected Functions
| Type | Name |
|---|---|
| uint8_t | dayOfTheWeek (uint16_t y, uint8_t m, uint8_t d) const Calculates the day of the week for a given date. |
| virtual uint8_t | readReg (uint8_t reg, const void * pBuf, size_t size) Reads data from a specific DS3231M register via I2C. |
| virtual void | writeReg (uint8_t reg, const void * pBuf, size_t size) Writes data to a specific DS3231M register via I2C. |
Protected Static Functions
| Type | Name |
|---|---|
| uint8_t | bcd2bin (uint8_t val) Converts a BCD (Binary-Coded Decimal) value to BIN (Binary). |
| uint8_t | bin2bcd (uint8_t val) Converts a BIN (Binary) value to BCD (Binary-Coded Decimal). |
Public Attributes Documentation
variable rtc
Array to store RTC time and date data.
Public Functions Documentation
function DS3231M
Constructor of the DS3231M class.
Parameters:
pWirePeripheral used for I2C communication.
function begin
Initializes I2C communication.
Returns:
True if communication with the module succeeds, false if it fails.
function clearAlarm
Clears the alarm flags in the status register.
This is necessary after an alarm has been triggered so it can be activated again.
function disable32k
Disables the 32kHz square wave output on the SQW/INT pin.
function enable32k
Enables the 32kHz square wave output on the SQW/INT pin.
function getRTCTime
Gets the current RTC time.
Returns:
DateTime object containing the current time and date.
function getTemp
Gets the current temperature from the DS3231M sensor.
Returns:
Temperature in degrees Celsius (float).
function isAlarm
Checks if any alarm has been triggered.
Returns:
True if alarm 1 or alarm 2 has been triggered, false otherwise.
function lostPower
Checks if the RTC lost backup power.
Returns:
True if backup power was lost.
function setAlarm1
Sets the first RTC alarm (alarm 1).
Parameters:
dtDateTime object with the alarm time and date.typeAlarm type (e.g. every minute, every hour, every day, etc.).
function setAlarm2
Sets the second RTC alarm (alarm 2).
Parameters:
dtDateTime object with the alarm time and date.typeAlarm type (e.g. every minute, every hour, every day, etc.).
function setRTCTime
Sets the RTC time and date.
void DS3231M::setRTCTime (
uint16_t year,
uint8_t month,
uint8_t day,
uint8_t hour,
uint8_t minute,
uint8_t second
)
Parameters:
yearYear (e.g. 2024).monthMonth (1-12).dayDay (1-31).hourHour (0-23).minuteMinute (0-59).secondSecond (0-59).
function ~DS3231M
Destructor of the DS3231M class.
Protected Functions Documentation
function dayOfTheWeek
Calculates the day of the week for a given date.
Parameters:
yYear.mMonth.dDay.
Returns:
Day of the week (1 = Sunday, 2 = Monday, ..., 7 = Saturday).
function readReg
Reads data from a specific DS3231M register via I2C.
Parameters:
regRegister address to read from.pBufPointer to the buffer where read data will be stored.sizeNumber of bytes to read.
Returns:
The number of bytes read (0 in case of error or if no bytes were read).
function writeReg
Writes data to a specific DS3231M register via I2C.
Parameters:
regRegister address to write to.pBufPointer to the data buffer to write.sizeNumber of bytes to write.
Protected Static Functions Documentation
function bcd2bin
Converts a BCD (Binary-Coded Decimal) value to BIN (Binary).
Parameters:
valValue in BCD format.
Returns:
Value in BIN format.
function bin2bcd
Converts a BIN (Binary) value to BCD (Binary-Coded Decimal).
Parameters:
valValue in BIN format.
Returns:
Value in BCD format.
The documentation for this class was generated from the following file firmware/DS3231M.h