Zanduino / DS3231M

Access the DS3231M I2C Realtime Clock
GNU General Public License v3.0
15 stars 7 forks source link

no way to tell whether the clock is set. #13

Closed gvisca44 closed 3 years ago

gvisca44 commented 3 years ago

Is your feature request related to a problem? Please describe. Unless I missed it (and I apologise if I did), there is no way to tell whether the clock is set.

Refer page15 of datasheet: OSF: Oscillator stop flag. A logic 1 in this bit indicates that the oscillator either is stopped or was stopped for some period and could be used to judge the validity of the timekeeping data. This bit is set to logic 1 any time that the oscillator stops. This bit remains at logic 1 until written to logic 0. The following are examples of conditions that can cause the OSF bit to be set: 1) The first time power is applied. 2) The voltages present on both VCC and VBAT are insufficient to support the oscillator. 3) The EOSC bit is turned off in battery-backed mode. 4) External influences on the oscillator (i.e., noise, leakage, etc.).

Describe the solution you'd like Perhaps add a method to check the OSF flag of the STATUS register.

Suggested code (edit as you see fit).

bool DS3231M_Class::getOSF() 
{
  if(readByte(DS3231M_STATUS) & (1 << 7))  // check bit 7 of STATUS register.
  {
    return true ; 
  } else {
    return false ; 
  }
}

Describe alternatives you've considered

Additional context Add any other context or screenshots about the feature request here.

SV-Zanshin commented 3 years ago

I've added a new function [isStopped()](https://github.com/SV-Zanshin/DS3231M/wiki/isStopped()) in Version 1.0.5