-
-
Notifications
You must be signed in to change notification settings - Fork 127
RtcDS3231 object
RtcDS3231 object provides access to all the functions of the DS3231 module. Along with date and time, this also includes setting alarms, retrieving the temperature, enabling the 32 kHz pin, and defining the square wave pin.
Construct a Rtc object using the provided WIRE method.
T_WIRE_METHOD - the typename of the class to use for the wire method. TwoWire
is the normal hardware method class.
wire - the instance of the T_WIRE_METHOD to use. Wire
is the normal hardware instance to use.
Below is an example of how to create an instance of the object using the normal Arduino hardware Wire support.
#include <Wire.h>
#include <RtcDS3231.h>
RtcDS3231<TwoWire> Rtc(Wire);
If you want to use SoftwareWire library, you can replace the above with this and it will work.
#include <SoftwareWire.h>
#include <RtcDS3231.h>
SoftwareWire myWire(SDA, SCL); // replace with the pins you use
RtcDS3231<SoftwareWire> Rtc(myWire);
The normal begin method that should be called within Setup()
<return>, the error code from the last Wire transaction. After each method call below, you may check if this return value for an error. See https://www.arduino.cc/en/Reference/WireEndTransmission for values of this error.
<return>, the RTC has confidence in the date and time it returns. If this returns false it usually means the battery is dead or the date and time has never been set.
<return>, the actual clock is running on the RTC.
isRunning - set if the clock is running. If false then the time value will not progress.
dt - the date and time to set the RTC to.
<return>, the current date and time in the RTC.
<return>, the temperature the module is current reading
This will turn off and on the special pin that will give a pulse at 32kHz rate.
enable - true to enable the pin, false to disable it
piMode - the mode to have the SquareWave pin act as. One of the following values valid.
DS3231SquareWavePin_ModeNone - disable the pin
DS3231SquareWavePin_ModeBatteryBackup - the pin will trigger when the external power is lower than the battery power
DS3231SquareWavePin_ModeClock - the pin will trigger at the frequency defined by SetSquareWavePinClockFrequency()
DS3231SquareWavePin_ModeAlarmOne - the pin will trigger with alarm one
DS3231SquareWavePin_ModeAlarmTwo - the pin will trigger with alarm two
DS3231SquareWavePin_ModeAlarmBoth - the pin will trigger with either of the alarms
When the SquareWave pin is enabled for the clock, this method will set at what frequency the pin will pulse.
freq - One of the follow is used to control it.
DS3231SquareWaveClock_1Hz - one per second
DS3231SquareWaveClock_1kHz - 1024 times per second
DS3231SquareWaveClock_4kHz - 4096 times a second
DS3231SquareWaveClock_8kHz - 8192 times a second
void SetAlarmOne(const DS3231AlarmOne& alarm)
Alarm one allows for setting an alarm that is accurate to the second with various modes.
alarm - a structure that defines all the properties to set the alarm one.
DS3231AlarmOne GetAlarmOne()
this will get the current settings for alarm one.
<return>, the structure for the current settings
void SetAlarmTwo(const DS3231AlarmTwo& alarm)
Alarm two allows for setting an alarm that is accurate to the minute with various modes.
alarm - a structure that defines all the properties to set the alarm two.
DS3231AlarmTwo GetAlarmTwo()
this will get the current settings for alarm two.
<return>, the structure for the current settings
This method must be called after an alarm is triggered otherwise it will not trigger again. It is used as a means to confirm you handled the alarm.
<return>, the flag that defines which alarms were still active when this method is called. The values can be checked using bit operations.
DS3231AlarmFlag_Alarm1 - flag value for alarm 1
DS3231AlarmFlag_Alarm2 - flag value for alarm 2
DS3231AlarmFlag_AlarmBoth - a value handy for checking for both
This will trigger a temperature compensation update internally to the RTC. This is used to more accurately keep time. It is rare that this needed as it already happens automatically about every 64 seconds.
block - set to true to not return from this call until the compensation update is finished.
(see DS3231 documentation)
Normal operation to keep the RTC Module within its accuracy specification does not require the user to manipulation the aging offset.
(see DS3231 documentation)
Normal operation to keep the RTC Module within its accuracy specification does not require the user to manipulation the aging offset.