2025-07-10 3:01 AM
Hi Master:
Platform: STM32H743
HAL library firmware: STM32Cube FW_H7 V1.12.1
Question:
As shown in the following code, it takes a long time to update 'sTime', perhaps a few minutes.
RTC_TimeTypeDef sTime = { 0 };
RTC_DateTypeDef sDate = { 0 };
ASSERT(HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN) == HAL_OK);
ASSERT(HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN) == HAL_OK);
But when I switch the order of execution, it is updated every second
RTC_TimeTypeDef sTime = { 0 };
RTC_DateTypeDef sDate = { 0 };
ASSERT2(HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN) == HAL_OK);
ASSERT2(HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN) == HAL_OK);
What is the reason for this? Thank you so much
Solved! Go to Solution.
2025-07-10 3:32 AM
Hello @Lyu.1
To ensure consistent and correct behavior, always follow the recommended order of reading the RTC registers:
Higher order means less frequently updated. Lowest order is the SSR, highest order is DR. The read must be done from lower order to higher order to have consistent result, because low order register read freezes higher order registers in the shadow zone. That's why your code produces the weird inconsistent updates.
Please refer to the example below:
2025-07-10 3:32 AM
Hello @Lyu.1
To ensure consistent and correct behavior, always follow the recommended order of reading the RTC registers:
Higher order means less frequently updated. Lowest order is the SSR, highest order is DR. The read must be done from lower order to higher order to have consistent result, because low order register read freezes higher order registers in the shadow zone. That's why your code produces the weird inconsistent updates.
Please refer to the example below:
2025-07-10 5:35 AM
Hi,
The RTC time and date registers are locked together.
Always call HAL_RTC_GetTime() before HAL_RTC_GetDate() to get up-to-date values.
HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN); // Get time first
HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN); // Then get date
2025-07-10 7:57 PM
Ok, thank you again
2025-07-10 7:57 PM
OK, thank you again