STM32 HAL库读取RTC时钟时间更新不正常
问题:
HAL_RTC_GetDate(&hrtc, &rtc_date, RTC_FORMAT_BIN);
HAL_RTC_GetTime(&hrtc, &rtc_time, RTC_FORMAT_BIN);
解决方案:
HAL_RTC_GetTime(&hrtc, &rtc_time, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &rtc_date, RTC_FORMAT_BIN);
原因:
You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values
in the higher-order calendar shadow registers to ensure consistency between the time and
date values.Reading RTC current time locks the values in calendar shadow registers until
Current date is read to ensure consistency between the time and date values.
即必须在HAL_RTC_GetTime()之后调用HAL_RTC_GetDate()来解锁高阶日历阴影寄存器中的值,以确保时间和日期值之间的一致性,否则会被上锁。
|