Skip to content

Commit ad4b54c

Browse files
committed
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
1 parent de4016b commit ad4b54c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/RTCZero.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,16 @@ void RTCZero::setEpoch(uint32_t ts)
420420
time_t t = ts;
421421
struct tm* tmp = gmtime(&t);
422422

423-
RTC->MODE2.CLOCK.bit.YEAR = tmp->tm_year - EPOCH_TIME_YEAR_OFF;
424-
RTC->MODE2.CLOCK.bit.MONTH = tmp->tm_mon + 1;
425-
RTC->MODE2.CLOCK.bit.DAY = tmp->tm_mday;
426-
RTC->MODE2.CLOCK.bit.HOUR = tmp->tm_hour;
427-
RTC->MODE2.CLOCK.bit.MINUTE = tmp->tm_min;
428-
RTC->MODE2.CLOCK.bit.SECOND = tmp->tm_sec;
423+
RTC_MODE2_CLOCK_Type clockTime;
424+
425+
clockTime.bit.YEAR = tmp->tm_year - EPOCH_TIME_YEAR_OFF;
426+
clockTime.bit.MONTH = tmp->tm_mon + 1;
427+
clockTime.bit.DAY = tmp->tm_mday;
428+
clockTime.bit.HOUR = tmp->tm_hour;
429+
clockTime.bit.MINUTE = tmp->tm_min;
430+
clockTime.bit.SECOND = tmp->tm_sec;
431+
432+
RTC->MODE2.CLOCK.reg = clockTime.reg;
429433

430434
while (RTCisSyncing())
431435
;

0 commit comments

Comments
 (0)