2023-11-17 08:23 AM
Using the RTC on a NUCLEO-G071RB (HAL) I have a program the prints out the time, date and temperature in degrees Centigrade. I left it running overnight and discovered in the morning that the hours had not reset to 00:00 at midnight and neither had the date rolled forward by a day.
I'm not experienced in embedded systems, in fact this is my first attempt at programming any MCU, but I thought this rollover was implemented in the HAL library.
I'm using functions HAL_RTC_SetTime & HAL_RTC_SetDate to initialise the clock to 10 seconds before midnight) and then HAL_RTC_GetTime and HAL_RTC_GetDate before printing to the serial monitor.
I'm not asking to fix my code (attached) but would appreciate help in knowing where to look. Thanks
Solved! Go to Solution.
2023-11-17 11:10 AM
Always start debugging with reading out and checking the relevant peripheral registers, here, RTC registers.
You'll find that you have RTC_CR.FMT set, i.e. RTC is in AM/PM (12-hour) mode, as a consequence of using uninitialized local variable as an initialization struct when calling Cube/HAL functions. Here, it's unitialized fields of hrtc in calling HAL_RTC_Init() (it's a weird call, as you've already called it in MX_RTC_Init()).
JW
2023-11-17 11:10 AM
Always start debugging with reading out and checking the relevant peripheral registers, here, RTC registers.
You'll find that you have RTC_CR.FMT set, i.e. RTC is in AM/PM (12-hour) mode, as a consequence of using uninitialized local variable as an initialization struct when calling Cube/HAL functions. Here, it's unitialized fields of hrtc in calling HAL_RTC_Init() (it's a weird call, as you've already called it in MX_RTC_Init()).
JW
2023-11-18 01:07 AM
Thanks Jan, that seems to have solved the problem. I initialised my gtime and gdate structs to {0} and now it works.
2023-11-18 01:11 AM
Hi Dabbo,
I was talking about the hrtc struct, defined locally in main().
JW