if(PauseClock)
{
if(rtc_i2c_read_byte(0xE,StatusByte))
But it should be 0x0F:
https://datasheets.maximintegrated.com/en/ds/DS3231.pdf
Status Register (0Fh)
Bit 7: Oscillator Stop Flag (OSF).
....
On a related matter: Initially I agreed with the comments in code regarding the small possibility of a race condition and therefore missing the alarm. Hence the PauseClock option. However, given this code has had the wrong register in it since it was first published and given it is a popular library which has been used by thousands (?) of people, and no one ever complained about missing alarms... It's a hint.
Really, IMHO, this concern is just deeply flawed. This is the code.
rtc_i2c_read_byte(0xF,StatusByte);
if(StatusByte & 0x3)
{
// Clear the alarm
rtc_i2c_write_byte(0xF,StatusByte & ~0x3);
}
You are only clearing the flag when it is set. So how can you "miss it"?
- If you clear it, it was set, so by definition you have not missed it?
- If it's not set when you do the read, then you won't clear it, and you will not detect (!) the alarm on this call of checkAlarm. But you will catch it on the next call? (this presumes polling, which is what this method is for, rather than interrupt).
Sorry if I have misunderstood something, but it seems to me that you are "treating a symptom that doesn't exist (missing alarms) with a placebo (writing to the wrong register)."
The only situation where your concern might still be valid, is if when using 2 alarms simultaneously. Ie 1 is set on read and 2 is not set, then 2 becomes set before we write and clear it. But even that is flawed if we (reasonably) assume that the DS3231 uses the same time in seconds to set both flags or none. So again you are not going to miss anything ...?
IMHO, the PauseClock param should be removed (complete with code writing to incorrect register). And same for the comments outlining the concern. The concern is not valid.