Merge pull request #786 from notro/rtc_set_datetime_precision

atmel-samd: RTC: Improve precision when setting datetime
This commit is contained in:
Scott Shawcroft 2018-04-29 20:30:37 -07:00 committed by GitHub
commit dd0f8689a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -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) { 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 = { struct calendar_date date = {
.year = tm->tm_year, .year = tm->tm_year,
.month = tm->tm_mon, .month = tm->tm_mon,