RTClib
Public Member Functions | Static Public Member Functions | List of all members
RTC_DS3231 Class Reference

RTC based on the DS3231 chip connected via I2C and the Wire library. More...

#include <RTClib.h>

Inheritance diagram for RTC_DS3231:
RTC_I2C

Public Member Functions

bool begin (TwoWire *wireInstance=&Wire)
 Start I2C for the DS3231 and test succesful connection. More...
 
void adjust (const DateTime &dt)
 Set the date and flip the Oscillator Stop Flag. More...
 
bool lostPower (void)
 Check the status register Oscillator Stop Flag to see if the DS3231 stopped due to power loss. More...
 
DateTime now ()
 Get the current date/time. More...
 
Ds3231SqwPinMode readSqwPinMode ()
 Read the SQW pin mode. More...
 
void writeSqwPinMode (Ds3231SqwPinMode mode)
 Set the SQW pin mode. More...
 
bool setAlarm1 (const DateTime &dt, Ds3231Alarm1Mode alarm_mode)
 Set alarm 1 for DS3231. More...
 
bool setAlarm2 (const DateTime &dt, Ds3231Alarm2Mode alarm_mode)
 Set alarm 2 for DS3231. More...
 
DateTime getAlarm1 ()
 Get the date/time value of Alarm1. More...
 
DateTime getAlarm2 ()
 Get the date/time value of Alarm2. More...
 
Ds3231Alarm1Mode getAlarm1Mode ()
 Get the mode for Alarm1. More...
 
Ds3231Alarm2Mode getAlarm2Mode ()
 Get the mode for Alarm2. More...
 
void disableAlarm (uint8_t alarm_num)
 Disable alarm. More...
 
void clearAlarm (uint8_t alarm_num)
 Clear status of alarm. More...
 
bool alarmFired (uint8_t alarm_num)
 Get status of alarm. More...
 
void enable32K (void)
 Enable 32KHz Output. More...
 
void disable32K (void)
 Disable 32KHz Output.
 
bool isEnabled32K (void)
 Get status of 32KHz Output. More...
 
float getTemperature ()
 Get the current temperature from the DS3231's temperature sensor. More...
 

Static Public Member Functions

static uint8_t dowToDS3231 (uint8_t d)
 Convert the day of the week to a representation suitable for storing in the DS3231: from 1 (Monday) to 7 (Sunday). More...
 

Detailed Description

RTC based on the DS3231 chip connected via I2C and the Wire library.

Member Function Documentation

◆ begin()

bool RTC_DS3231::begin ( TwoWire *  wireInstance = &Wire)

Start I2C for the DS3231 and test succesful connection.

Parameters
wireInstancepointer to the I2C bus
Returns
True if Wire can find DS3231 or false otherwise.

◆ adjust()

void RTC_DS3231::adjust ( const DateTime dt)

Set the date and flip the Oscillator Stop Flag.

Parameters
dtDateTime object containing the date/time to set

◆ lostPower()

bool RTC_DS3231::lostPower ( void  )

Check the status register Oscillator Stop Flag to see if the DS3231 stopped due to power loss.

Returns
True if the bit is set (oscillator stopped) or false if it is running

◆ now()

DateTime RTC_DS3231::now ( )

Get the current date/time.

Returns
DateTime object with the current date/time

◆ readSqwPinMode()

Ds3231SqwPinMode RTC_DS3231::readSqwPinMode ( )

Read the SQW pin mode.

Returns
Pin mode, see Ds3231SqwPinMode enum

◆ writeSqwPinMode()

void RTC_DS3231::writeSqwPinMode ( Ds3231SqwPinMode  mode)

Set the SQW pin mode.

Parameters
modeDesired mode, see Ds3231SqwPinMode enum

◆ setAlarm1()

bool RTC_DS3231::setAlarm1 ( const DateTime dt,
Ds3231Alarm1Mode  alarm_mode 
)

Set alarm 1 for DS3231.

Parameters
dtDateTime object
alarm_modeDesired mode, see Ds3231Alarm1Mode enum
Returns
False if control register is not set, otherwise true

◆ setAlarm2()

bool RTC_DS3231::setAlarm2 ( const DateTime dt,
Ds3231Alarm2Mode  alarm_mode 
)

Set alarm 2 for DS3231.

Parameters
dtDateTime object
alarm_modeDesired mode, see Ds3231Alarm2Mode enum
Returns
False if control register is not set, otherwise true

◆ getAlarm1()

DateTime RTC_DS3231::getAlarm1 ( )

Get the date/time value of Alarm1.

Returns
DateTime object with the Alarm1 data set in the day, hour, minutes, and seconds fields

◆ getAlarm2()

DateTime RTC_DS3231::getAlarm2 ( )

Get the date/time value of Alarm2.

Returns
DateTime object with the Alarm2 data set in the day, hour, and minutes fields

◆ getAlarm1Mode()

Ds3231Alarm1Mode RTC_DS3231::getAlarm1Mode ( )

Get the mode for Alarm1.

Returns
Ds3231Alarm1Mode enum value for the current Alarm1 mode

◆ getAlarm2Mode()

Ds3231Alarm2Mode RTC_DS3231::getAlarm2Mode ( )

Get the mode for Alarm2.

Returns
Ds3231Alarm2Mode enum value for the current Alarm2 mode

◆ disableAlarm()

void RTC_DS3231::disableAlarm ( uint8_t  alarm_num)

Disable alarm.

Parameters
alarm_numAlarm number to disable

◆ clearAlarm()

void RTC_DS3231::clearAlarm ( uint8_t  alarm_num)

Clear status of alarm.

Parameters
alarm_numAlarm number to clear

◆ alarmFired()

bool RTC_DS3231::alarmFired ( uint8_t  alarm_num)

Get status of alarm.

Parameters
alarm_numAlarm number to check status of
Returns
True if alarm has been fired otherwise false

◆ enable32K()

void RTC_DS3231::enable32K ( void  )

Enable 32KHz Output.

The 32kHz output is enabled by default. It requires an external pull-up resistor to function correctly

◆ isEnabled32K()

bool RTC_DS3231::isEnabled32K ( void  )

Get status of 32KHz Output.

Returns
True if enabled otherwise false

◆ getTemperature()

float RTC_DS3231::getTemperature ( )

Get the current temperature from the DS3231's temperature sensor.

Returns
Current temperature (float)

◆ dowToDS3231()

static uint8_t RTC_DS3231::dowToDS3231 ( uint8_t  d)
inlinestatic

Convert the day of the week to a representation suitable for storing in the DS3231: from 1 (Monday) to 7 (Sunday).

Parameters
dDay of the week as represented by the library: from 0 (Sunday) to 6 (Saturday).
Returns
the converted value

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