Skip to content

Commit d37cf3b

Browse files
committed
Added a fix for the default CLOCK register value of 0.
The default CLOCK register value of 0 is not a valid time. When the RTC was reset (either by POR or by the user's choice), the start value of 0 was invalid. This automatically corrected after one second elapsed causing a jump in the epoch time (of 1 month + 1 day).
1 parent f3d2587 commit d37cf3b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/RTCZero.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,15 @@ void RTCZero::begin(bool resetTime)
8383
RTCenable();
8484
RTCresetRemove();
8585

86-
// If desired and valid, restore the time value
86+
// If desired and valid, restore the time value, else use first valid time value
8787
if ((!resetTime) && (validTime)) {
8888
RTC->MODE2.CLOCK.reg = oldTime.reg;
89-
while (RTCisSyncing())
90-
;
9189
}
90+
else {
91+
RTC->MODE2.CLOCK.reg = RTC_MODE2_CLOCK_MONTH(1) | RTC_MODE2_CLOCK_DAY(1);
92+
}
93+
while (RTCisSyncing())
94+
;
9295

9396
_configured = true;
9497
}

0 commit comments

Comments
 (0)