I'm using STM32F030RCT6 with CubeMX. Device is a datalogger and RTC is the main think that cannot fail. On Errata Sheet there is something about RTC Shadow Register.
I configured CubeMX to not generate MX_RTC_Init() function and it has been working normally so far. (I'm using LSE)
I need to update the time/date from GSM time but when i set the year to 18 with HAL_SetDate() and after a small delay i read with HAL_GetDate() and sDate. Year gave me 20. Apart from Year the other values are correct.
What I tried:
- LSI Used
- while(SetDate!=GetDate) SetDate(ActualDate)
- First SetTime then SetDate
I got no progress and even getting worse like Month = 56, Day = 45 etc.
Thanks in advance. Best regards.
I had exactly the same issue with setting the year value after using
HAL_SetDate()
. Wrong values was read with theHal_GetDate()
function.MX_RTC_Init()
checks first a particular value in a RTC BKP register to know if a Reset occurred on the RTC domain. It prevents from setting again the time and date if it has been already done.I finally did the same and tadaaaam for the first time I'm reading a good year value of 18 !!
I do not understand precisely why it works, I'll ask on ST forum and edit this answer as soon as I know.
In the meantime could you check if it works for you too ?
I had the same problem. I found that the problem was not setting the WeekDay (when creating a struct RTC_DateTypeDef, the field WeekDay gets a random value). The value WeekDay must be set to a value between 0 to 7.
Explanation: The code for setting the date in function HAL_RTC_SetDate:
When WeekDay is greater than 7, it overlaps with the bits of Year and can change it.
Set your WeekDay parameter to a valid value