Skip to content

Commit 8f4174a

Browse files
committed
Added extra valid time test and default date and time.
1 parent d37cf3b commit 8f4174a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/RTCZero.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,14 @@ void RTCZero::begin(bool resetTime)
8484
RTCresetRemove();
8585

8686
// If desired and valid, restore the time value, else use first valid time value
87-
if ((!resetTime) && (validTime)) {
87+
if ((!resetTime) && (validTime) && (oldTime.reg != 0L)) {
8888
RTC->MODE2.CLOCK.reg = oldTime.reg;
8989
}
9090
else {
91-
RTC->MODE2.CLOCK.reg = RTC_MODE2_CLOCK_MONTH(1) | RTC_MODE2_CLOCK_DAY(1);
91+
// Change the values here to set a default date and time
92+
// Use calendar year-2000, month and day values cannot be 0
93+
RTC->MODE2.CLOCK.reg = RTC_MODE2_CLOCK_YEAR(0) | RTC_MODE2_CLOCK_MONTH(1) | RTC_MODE2_CLOCK_DAY(1)
94+
| RTC_MODE2_CLOCK_HOUR(0) | RTC_MODE2_CLOCK_MINUTE(0) | RTC_MODE2_CLOCK_SECOND(0);
9295
}
9396
while (RTCisSyncing())
9497
;

0 commit comments

Comments
 (0)