cancel
Showing results for 
Search instead for 
Did you mean: 

RTC not changing in Nucleo-F746ZG?

TMeeh.1
Associate II

Hi - I have a Nucleo-F746ZG that I am configuring in CubeMX (version 6.2.1). When configuring it I am trying to only set up the RTC and UART3. UART3 is set up to print to the USB virtual COM port (and that works fine).

In CubeMX, once I start a new project, I go to the "Timers" tab, the to the "RTC" node, then select the checkbox for "Activate Clock Source."

The only changes I made to the generated source code were in the main method. I understand from reading the source code for stm32f7xx_hal_rtc.c that it is important to call HAL_RTC_GetTime and then call HAL_RTC_GetDate.

Inside of main, in USER CODE BEGIN 2:

RTC_TimeTypeDef current_time;                                                 
RTC_DateTypeDef current_date;
HAL_RTC_GetTime(&hrtc, &current_time, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &current_date, RTC_FORMAT_BIN);
printf("    H:M:S = %02d:%02d:%02d\r\n", current_time.Hours, current_time.Minutes, current_time.Seconds);
HAL_Delay(2000);                                                              
printf("    H:M:S = %02d:%02d:%02d\r\n", current_time.Hours, current_time.Minutes, current_time.Seconds);

I was expecting to see "09:05:00" followed by "09:05:02" because of the 2 second delay inserted by HAL_Delay. What I got was "09:05:00" followed by the same thing.

I didn't see a "start" function in the API for the RTC. What else am I missing?

I tried this with two different Nucleo-F746ZG boards.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

> RTC_TimeTypeDef current_time;

> RTC_DateTypeDef current_date;

> HAL_RTC_GetTime(&hrtc, &current_time, RTC_FORMAT_BIN);

> HAL_RTC_GetDate(&hrtc, &current_date, RTC_FORMAT_BIN);

> printf(" H:M:S = %02d:%02d:%02d\r\n", current_time.Hours, current_time.Minutes, current_time.Seconds);

> HAL_Delay(2000);

> printf(" H:M:S = %02d:%02d:%02d\r\n", current_time.Hours, current_time.Minutes, current_time.Seconds);

You need to get the time again if you want it to be updated. You're just re-printing the old time. Call HAL_RTC_GetTime/HAL_RTC_GetDate again.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

4 REPLIES 4
TDK
Guru

> RTC_TimeTypeDef current_time;

> RTC_DateTypeDef current_date;

> HAL_RTC_GetTime(&hrtc, &current_time, RTC_FORMAT_BIN);

> HAL_RTC_GetDate(&hrtc, &current_date, RTC_FORMAT_BIN);

> printf(" H:M:S = %02d:%02d:%02d\r\n", current_time.Hours, current_time.Minutes, current_time.Seconds);

> HAL_Delay(2000);

> printf(" H:M:S = %02d:%02d:%02d\r\n", current_time.Hours, current_time.Minutes, current_time.Seconds);

You need to get the time again if you want it to be updated. You're just re-printing the old time. Call HAL_RTC_GetTime/HAL_RTC_GetDate again.

If you feel a post has answered your question, please click "Accept as Solution".
SBEN .2
Senior II

Hello @TMeeh.1​ ,

You need to get the date another time before re-displaying it:

RTC_TimeTypeDef current_time;                                                 
RTC_DateTypeDef current_date;
HAL_RTC_GetTime(&hrtc, &current_time, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &current_date, RTC_FORMAT_BIN);
printf("    H:M:S = %02d:%02d:%02d\r\n", current_time.Hours, current_time.Minutes, current_time.Seconds);
HAL_Delay(2000);                                                              
HAL_RTC_GetTime(&hrtc, &current_time, RTC_FORMAT_BIN);
printf("    H:M:S = %02d:%02d:%02d\r\n", current_time.Hours, current_time.Minutes, current_time.Seconds);

Best regards,

@SBEN .2​ 

TMeeh.1
Associate II

Ha! I was afraid that it was something silly, and it was.

Don't worry @TMeeh.1​ , it happens to the best of us :)