2021-06-30 11:43 AM
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, ¤t_time, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, ¤t_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.
Solved! Go to Solution.
2021-06-30 12:11 PM
> RTC_TimeTypeDef current_time;
> RTC_DateTypeDef current_date;
> HAL_RTC_GetTime(&hrtc, ¤t_time, RTC_FORMAT_BIN);
> HAL_RTC_GetDate(&hrtc, ¤t_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.
2021-06-30 12:11 PM
> RTC_TimeTypeDef current_time;
> RTC_DateTypeDef current_date;
> HAL_RTC_GetTime(&hrtc, ¤t_time, RTC_FORMAT_BIN);
> HAL_RTC_GetDate(&hrtc, ¤t_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.
2021-06-30 12:16 PM
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, ¤t_time, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, ¤t_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, ¤t_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
2021-06-30 12:58 PM
Ha! I was afraid that it was something silly, and it was.
2021-06-30 10:41 PM
Don't worry @TMeeh.1 , it happens to the best of us :)