diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2018-04-29 20:30:37 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-29 20:30:37 -0700 |
| commit | dd0f8689a135b33dbeedaefdfa149fd7ec3c94e8 (patch) | |
| tree | c010be6fa05cdfbcbb337a59a0a44e4f15f438e1 /ports | |
| parent | 6855541e33e4ac3f6413c19c1f5fff9be091cca2 (diff) | |
| parent | 62d7a800d76ffb020d0cb1076b54a8e049b08bee (diff) | |
Merge pull request #786 from notro/rtc_set_datetime_precision
atmel-samd: RTC: Improve precision when setting datetime
Diffstat (limited to 'ports')
| -rw-r--r-- | ports/atmel-samd/common-hal/rtc/RTC.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/ports/atmel-samd/common-hal/rtc/RTC.c b/ports/atmel-samd/common-hal/rtc/RTC.c index d63e81305..680a88deb 100644 --- a/ports/atmel-samd/common-hal/rtc/RTC.c +++ b/ports/atmel-samd/common-hal/rtc/RTC.c @@ -64,6 +64,12 @@ void common_hal_rtc_get_time(timeutils_struct_time_t *tm) { } void common_hal_rtc_set_time(timeutils_struct_time_t *tm) { + // Reset prescaler to increase initial precision. Otherwise we can be up to 1 second off already. + uint32_t freqcorr = hri_rtcmode0_read_FREQCORR_reg(calendar.device.hw); + calendar_deinit(&calendar); + rtc_init(); + hri_rtcmode0_write_FREQCORR_reg(calendar.device.hw, freqcorr); + struct calendar_date date = { .year = tm->tm_year, .month = tm->tm_mon, |
