arduino-libraries / RTCZero

RTC Library for SAMD21 based boards
http://arduino.cc/en/Reference/RTC
GNU Lesser General Public License v2.1
78 stars 78 forks source link

Calling setEpoch causes serial data / interrupts to be lost #44

Closed jetty840 closed 5 years ago

jetty840 commented 5 years ago

Calling setEpoch causes serial data to be lost. This is because the CLOCK register is altered bit by bit sequentially without the SYNCBUSY bit being checked with each update.

This causes a bus stall and serial interrupts to be lost. As per the datasheet - section 19.6.8 (Synchronization):

"When executing an operation that requires synchronization, the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set immediately, and cleared when synchronization is complete.... If an operation that requires synchronization is executed while STATUS.SYNCBUSY is one, the bus will be stalled... Clock Value register (CLOCK)"

These changes fix this by changing all the single bit change updates into one register change followed by a SYNCBUSY check.