STM32F103C8T6 RTC year keeps defaulting to 2000, time however OK
Strange problem.
The RTC seems to be working.
Once set up, the RTC time is working but when CPU does power cycle, the time is OK, but the year keeps defaulting to 2000.
It is probably I’m doing something wrong.
I set the clock using MX_RTC_Init() which has the time and date hard coded into it from the defaults it receives from STM23CubeMX setup.
The next time I run, I don’t run MX_RTC_Init()
(If I did, the hard coded time will be written back into the RTC).
and then run HAL_RTC_GetTime(&hrtc, &RTC_Time, RTC_FORMAT_BIN);
which fetches the battery backed time - the time is correct.
At this point, I am assuming all the data structures have initialised
properly even though I have not run MX_RTC_Init()
and then I do HAL_RTC_GetDate(&hrtc, &RTC_Date, RTC_FORMAT_BIN);
this however has defaulted the year to 2000.
This default date is being set I think in
HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc) which is in file stm32f1xx_hal_rtc.c
(I don’t think we are supposed to modify this file.)
The time function is OK, so Is there some step I missed to get the corret date out of the RTC?
TIA