1 parent 83e3907 commit 62d7a80Copy full SHA for 62d7a80
1 file changed
ports/atmel-samd/common-hal/rtc/RTC.c
@@ -64,6 +64,12 @@ void common_hal_rtc_get_time(timeutils_struct_time_t *tm) {
64
}
65
66
void common_hal_rtc_set_time(timeutils_struct_time_t *tm) {
67
+ // Reset prescaler to increase initial precision. Otherwise we can be up to 1 second off already.
68
+ uint32_t freqcorr = hri_rtcmode0_read_FREQCORR_reg(calendar.device.hw);
69
+ calendar_deinit(&calendar);
70
+ rtc_init();
71
+ hri_rtcmode0_write_FREQCORR_reg(calendar.device.hw, freqcorr);
72
+
73
struct calendar_date date = {
74
.year = tm->tm_year,
75
.month = tm->tm_mon,
0 commit comments