Skip to content

Commit

Permalink
DS3231: Add support for the Aging Offset Register
Browse files Browse the repository at this point in the history
  • Loading branch information
edgar-bonet committed Mar 23, 2024
1 parent 18154ba commit 4d19d98
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/RTC_DS3231.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define DS3231_ALARM2 0x0B ///< Alarm 2 register
#define DS3231_CONTROL 0x0E ///< Control register
#define DS3231_STATUSREG 0x0F ///< Status register
#define DS3231_AGINGREG 0x10 ///< Aging offset register
#define DS3231_TEMPERATUREREG \
0x11 ///< Temperature register (high byte - low byte is at 0x12), 10-bit
///< temperature value
Expand Down Expand Up @@ -382,3 +383,27 @@ void RTC_DS3231::disable32K(void) {
bool RTC_DS3231::isEnabled32K(void) {
return (read_register(DS3231_STATUSREG) >> 0x03) & 0x01;
}

/**************************************************************************/
/*!
@brief Get the value of the Aging Offset Register
@see setAgingOffset() for an explanation of this register
@return The current value of the Aging Offset Register
*/
/**************************************************************************/
int8_t RTC_DS3231::getAgingOffset() { return read_register(DS3231_AGINGREG); }

/**************************************************************************/
/*!
@brief Update the Aging Offset Register
@details The Aging Offset Register can be used to compensate for
systematic drift due to aging. A positive value makes the RTC
run slower, a negative value makes it run faster. The effect is
temperature dependent. At room temperature, the RTC frequency
changes by roughly 0.1 ppm per unit of offset.
@param offset New offset to be written into the register
*/
/**************************************************************************/
void RTC_DS3231::setAgingOffset(int8_t offset) {
write_register(DS3231_AGINGREG, offset);
}
2 changes: 2 additions & 0 deletions src/RTClib.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ class RTC_DS3231 : RTC_I2C {
void disable32K(void);
bool isEnabled32K(void);
float getTemperature(); // in Celsius degree
int8_t getAgingOffset();
void setAgingOffset(int8_t);
/*!
@brief Convert the day of the week to a representation suitable for
storing in the DS3231: from 1 (Monday) to 7 (Sunday).
Expand Down

0 comments on commit 4d19d98

Please sign in to comment.