6 #ifndef ACE_TIME_HW_DS3231_MODULE_H
7 #define ACE_TIME_HW_DS3231_MODULE_H
10 #include <AceCommon.h>
11 #include "HardwareDateTime.h"
12 #include "HardwareTemperature.h"
17 class HardwareDateTime;
18 class HardwareTemperature;
31 template <
typename T_WIREI>
34 static const uint8_t kAddress = 0x68;
38 explicit DS3231(
const T_WIREI& wireInterface) :
39 mWireInterface(wireInterface)
44 using ace_common::bcdToDec;
46 mWireInterface.beginTransmission(kAddress);
47 mWireInterface.write(0);
48 mWireInterface.endTransmission();
51 mWireInterface.requestFrom(kAddress, (uint8_t) 7);
52 dateTime->
second = bcdToDec(mWireInterface.read() & 0x7F);
53 dateTime->
minute = bcdToDec(mWireInterface.read());
54 dateTime->
hour = bcdToDec(mWireInterface.read() & 0x3F);
55 dateTime->
dayOfWeek = bcdToDec(mWireInterface.read());
56 dateTime->
day = bcdToDec(mWireInterface.read());
57 dateTime->
month = bcdToDec(mWireInterface.read());
58 dateTime->
year = bcdToDec(mWireInterface.read());
63 using ace_common::decToBcd;
65 mWireInterface.beginTransmission(kAddress);
66 mWireInterface.write(0);
67 mWireInterface.write(decToBcd(dateTime.
second));
68 mWireInterface.write(decToBcd(dateTime.
minute));
69 mWireInterface.write(decToBcd(dateTime.
hour));
70 mWireInterface.write(decToBcd(dateTime.
dayOfWeek));
71 mWireInterface.write(decToBcd(dateTime.
day));
72 mWireInterface.write(decToBcd(dateTime.
month));
73 mWireInterface.write(decToBcd(dateTime.
year));
74 mWireInterface.endTransmission();
79 mWireInterface.beginTransmission(kAddress);
80 mWireInterface.write(0x11);
81 mWireInterface.endTransmission();
83 mWireInterface.requestFrom(kAddress, (uint8_t) 2);
84 temperature->
msb = mWireInterface.read();
85 temperature->
lsb = mWireInterface.read();
89 const T_WIREI mWireInterface;
New version of the DS3231 class templatized so that any of the AceWire classes can be used to access ...
DS3231(const T_WIREI &wireInterface)
Constructor.
void readDateTime(HardwareDateTime *dateTime) const
Read the time into the HardwareDateTime object.
void setDateTime(const HardwareDateTime &dateTime) const
Set the DS3231 with the HardwareDateTime values.
void readTemperature(HardwareTemperature *temperature) const
Read the temperature into the HardwareTemperature object.
The date (year, month, day) and time (hour, minute, second) fields supported by the DS3231 RTC chip.
uint8_t year
[00, 99], year - 2000
uint8_t dayOfWeek
[1, 7], interpretation undefined, increments every day
The temperature in Celcius as a signed (8.8) fixed-point integer.
uint8_t msb
Upper byte of signed (8.8) fixed point temperature.
uint8_t lsb
Lower byte of signed (8.8) fixed point temperature.