33 #ifndef ERRIEZ_DS3231_H_ 34 #define ERRIEZ_DS3231_H_ 40 #define DS3231_REG_SECONDS 0x00 41 #define DS3231_REG_MINUTES 0x01 42 #define DS3231_REG_HOURS 0x02 43 #define DS3231_REG_DAY_WEEK 0x03 44 #define DS3231_REG_DAY_MONTH 0x04 45 #define DS3231_REG_MONTH 0x05 46 #define DS3231_REG_YEAR 0x06 48 #define DS3231_REG_ALARM1_SEC 0x07 49 #define DS3231_REG_ALARM1_MIN 0x08 50 #define DS3231_REG_ALARM1_HOUR 0x09 51 #define DS3231_REG_ALARM1_DD 0x0A 52 #define DS3231_REG_ALARM2_MIN 0x0B 53 #define DS3231_REG_ALARM2_HOUR 0x0C 54 #define DS3231_REG_ALARM2_DD 0x0D 56 #define DS3231_REG_CONTROL 0x0E 57 #define DS3231_REG_STATUS 0x0F 58 #define DS3231_REG_AGING_OFFSET 0x10 59 #define DS3231_REG_TEMP_MSB 0x11 60 #define DS3231_REG_TEMP_LSB 0x12 62 #define DS3231_NUM_REGS 19 65 #define DS3231_HOUR_12H_24H 6 67 #define DS3231_HOUR_AM_PM 5 69 #define DS3231_MONTH_CENTURY 7 71 #define DS3231_CTRL_EOSC 7 72 #define DS3231_CTRL_BBSQW 6 73 #define DS3231_CTRL_CONV 5 74 #define DS3231_CTRL_RS2 4 75 #define DS3231_CTRL_RS1 3 76 #define DS3231_CTRL_INTCN 2 77 #define DS3231_CTRL_A2IE 1 78 #define DS3231_CTRL_A1IE 0 80 #define DS3231_STAT_OSF 7 81 #define DS3231_STAT_EN32KHZ 3 82 #define DS3231_STAT_BSY 2 83 #define DS3231_STAT_A2F 1 84 #define DS3231_STAT_A1F 0 95 #define DS3231_ADDR (0xD0 >> 1) 99 #define SECONDS_FROM_1970_TO_2000 946684800 162 bool read(
struct tm *dt);
163 bool write(
const struct tm *dt);
164 bool setTime(uint8_t hour, uint8_t min, uint8_t sec);
165 bool getTime(uint8_t *hour, uint8_t *min, uint8_t *sec);
166 bool setDateTime(uint8_t hour, uint8_t min, uint8_t sec,
167 uint8_t mday, uint8_t mon, uint16_t year,
169 bool getDateTime(uint8_t *hour, uint8_t *min, uint8_t *sec,
170 uint8_t *mday, uint8_t *mon, uint16_t *year,
175 uint8_t dayDate, uint8_t hours, uint8_t minutes, uint8_t seconds);
202 bool readBuffer(uint8_t reg,
void *buffer, uint8_t len);
203 bool writeBuffer(uint8_t reg,
void *buffer, uint8_t len);
206 #endif // ERRIEZ_DS3231_H_ uint8_t readRegister(uint8_t reg)
Read register.
bool getDateTime(uint8_t *hour, uint8_t *min, uint8_t *sec, uint8_t *mday, uint8_t *mon, uint16_t *year, uint8_t *wday)
Get date time.
Alarm when minutes and seconds match.
bool alarmInterruptEnable(AlarmId alarmId, bool enable)
Enable or disable Alarm 1 or 2 interrupt.
uint8_t bcdToDec(uint8_t bcd)
BCD to decimal conversion.
time_t getEpoch()
Read Unix UTC epoch time_t.
bool clearAlarmFlag(AlarmId alarmId)
Clear alarm flag.
bool setAlarm1(Alarm1Type alarmType, uint8_t dayDate, uint8_t hours, uint8_t minutes, uint8_t seconds)
Set Alarm 1.
Alarm when day, hours, minutes, and seconds match.
bool startTemperatureConversion()
Start temperature conversion.
bool setAgingOffset(int8_t val)
Set aging offset register.
Alarm2Type
Alarm 2 types enum.
bool readBuffer(uint8_t reg, void *buffer, uint8_t len)
Read buffer from RTC.
bool setDateTime(uint8_t hour, uint8_t min, uint8_t sec, uint8_t mday, uint8_t mon, uint16_t year, uint8_t wday)
Set date time.
bool write(const struct tm *dt)
Write date and time to RTC.
#define DS3231_CTRL_INTCN
Interrupt control.
bool writeRegister(uint8_t reg, uint8_t value)
Write register.
Alarm when hours, minutes, and seconds match.
Alarm when hours and minutes match.
bool read(struct tm *dt)
Read date and time from RTC.
uint8_t decToBcd(uint8_t dec)
Decimal to BCD conversion.
bool getTime(uint8_t *hour, uint8_t *min, uint8_t *sec)
Read time from RTC.
#define DS3231_CTRL_RS1
Square wave rate-select 1.
#define DS3231_CTRL_RS2
Square wave rate-select 2.
Alarm once per minute (00 seconds of every minute)
bool clockEnable(bool enable=true)
Enable or disable oscillator when running on V-BAT.
bool setTime(uint8_t hour, uint8_t min, uint8_t sec)
Write time to RTC.
Alarm1Type
Alarm 1 types enum.
bool setEpoch(time_t t)
Write Unix epoch UTC time to RTC.
bool getTemperature(int8_t *temperature, uint8_t *fraction)
Read temperature.
Alarm when seconds match.
bool getAlarmFlag(AlarmId alarmId)
Get Alarm 1 or 2 flag.
Alarm when minutes match.
Alarm when day, hours, and minutes match.
bool begin()
Initialize and detect DS3231 RTC.
bool isRunning()
Read RTC OSF (Oscillator Stop Flag) from status register.
bool setAlarm2(Alarm2Type alarmType, uint8_t dayDate, uint8_t hours, uint8_t minutes)
Set Alarm 2.
Alarm when date, hours, minutes, and seconds match.
bool writeBuffer(uint8_t reg, void *buffer, uint8_t len)
Write buffer to RTC.
Alarm when date, hours, and minutes match.
bool setSquareWave(SquareWave squareWave)
Configure SQW (Square Wave) output pin.
SquareWave
Squarewave enum.
int8_t getAgingOffset()
Get aging offset register.
bool outputClockPinEnable(bool enable)
Enable or disable 32kHz output clock pin.