r-map / rmap

rete monitoraggio ambientale partecipativo documentation at https://doc.rmap.cc
https://rmap.cc
52 stars 43 forks source link

firmware: pcf8563 library, setting date and time is not atomic #353

Closed pat1 closed 2 years ago

pat1 commented 2 years ago

Setting and reading the time During read/write operations, the time counting circuits (memory locations 02h through 08h) are blocked. This prevents

After this read/write access is completed, the time circuit is released again and any pending request to increment the time counters that occurred during the read access is serviced. A maximum of 1 request can be stored; therefore, all accesses must be completed within 1 second. As a consequence of this method, it is very important to make a read or write access in one go, that is, setting or reading seconds through to years should be made in one single access. Failing to comply with this method could result in the time becoming corrupted. As an example, if the time (seconds through to hours) is set in one access and then in a second access the date is set, it is possible that the time may increment between the two accesses. A similar problem exists when reading. A roll over may occur between reads thus giving the minutes from one moment and the hours from the next. Recommended method for reading the time:

  1. Send a START condition and the slave address for write (A2h).
  2. Set the address pointer to 2 (VL_seconds) by sending 02h.
  3. Send a RESTART condition or STOP followed by START.
  4. Send the slave address for read (A3h).
  5. Read VL_seconds.
  6. Read Minutes.
  7. Read Hours.
  8. Read Days.
  9. Read Weekdays.
  10. Read Century_months.
  11. Read Years.
  12. Send a STOP condition