Skip to content

Commit dd0f868

Browse files
authored
Merge pull request adafruit#786 from notro/rtc_set_datetime_precision
atmel-samd: RTC: Improve precision when setting datetime
2 parents 6855541 + 62d7a80 commit dd0f868

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

  • ports/atmel-samd/common-hal/rtc

ports/atmel-samd/common-hal/rtc/RTC.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ void common_hal_rtc_get_time(timeutils_struct_time_t *tm) {
6464
}
6565

6666
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+
6773
struct calendar_date date = {
6874
.year = tm->tm_year,
6975
.month = tm->tm_mon,

0 commit comments

Comments
 (0)