Skip to main content
Lyu.1
Senior
Jul 10, 2025 10:01 AM UTC
Solved

‘HAL_RTC_GetTime’ was not updating the time.

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

This topic has been closed for replies.
Saket_OmBest answer
ST Technical Moderator
Jul 10, 2025 10:32 AM UTC

Hello @Lyu.1 

To ensure consistent and correct behavior, always follow the recommended order of reading the RTC registers:

  1. Read the time first using HAL_RTC_GetTime().
  2. Then read the date using HAL_RTC_GetDate()

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: 

STM32CubeH7/Projects/NUCLEO-H743ZI/Examples/RTC/RTC_TimeStamp at master · STMicroelectronics/STM32CubeH7 · GitHub

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om

4 replies

Saket_OmBest answer
ST Technical Moderator
Jul 10, 2025 10:32 AM UTC

Hello @Lyu.1 

To ensure consistent and correct behavior, always follow the recommended order of reading the RTC registers:

  1. Read the time first using HAL_RTC_GetTime().
  2. Then read the date using HAL_RTC_GetDate()

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: 

STM32CubeH7/Projects/NUCLEO-H743ZI/Examples/RTC/RTC_TimeStamp at master · STMicroelectronics/STM32CubeH7 · GitHub

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
Lyu.1
Lyu.1Author
Senior
Jul 11, 2025 2:57 AM UTC

Ok, thank you again

Associate
Jul 10, 2025 12:35 PM UTC

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

Lyu.1
Lyu.1Author
Senior
Jul 11, 2025 2:57 AM UTC

OK, thank you again