AnsweredAssumed Answered

RTC Misbehavior and strange display

Question asked by Elliot on Dec 13, 2016
Hi,
I'm working with STM32L486RG ultra low power microcontroller using the IAR v7.4 IDE.
I'm using the RTC peripheral in order to get the real time clock . My clock source is an LSE crystal which has 32768Hz as frequency.
I developed simple APIs based on the stm32L4xx_rtc_hal.c APIs in order to set and get time from a given POSIX value.
But unfortunately , problems have showed out and I figured mysterious behaviors with my RTC.Below I'm listing all the issues :
1- Problem with correct Date display ( Issue appears when I use Binary format instead of BCD format) :
In fact, I have followed the RTC_TimeStamp example provided by STMicroelectronics within its STM32L4xx HAL package.
In this example, we do use the BCD FORMAT while setting date and time and we do use the BIN FORMAT when getting date and time.
I have tried to do so with my project. My date and time are 2017/01/01 - 00:00:00 which have the corresponding POSIX value 1483228800.
When I use binary format ( BIN format ) to get the date , I found 2011/01/01 as date value ( which is obviously wrong. Now, as first step I have switched to BCD format for getting the date and I have the right date value which is 2017/01/01 
(see attached capture named "Date_with_BCD_format"). So, as an initial deduction, I might asked if there's a problem with the way ST converts date from BCD
to BIN through its HAL APIs. After debugging, I found that "RTC_Bcd2ToByte" function used by "HAL_RTC_GetDate" is returning a wrong value.
Can someone confirm this behavior ? Maybe there's something missing with my configuration ?
2- RTC_TR register has shown a problem when incrementing :
I have set this time 2016/12/31 - 23:59:59 but when I get time after incrementation , I figured out that the date didn't change. I checked then
the RTC_TR register and I found that the hours value in the RTC_TR register is 0x17 ( which is exactly 23h ) the minutes value is 0x3B ( which is exactly
59m ) and the seconds value is 0x3B ( which is exactly 59s ) (see capture named "RTC_Registers_23h59m59s" ). Now, after incrementation , we shall see that hours value becomes 0x00 as well as minutes value 
and seconds value should restart counting from 0x00 to 0x3B in order to increment the minutes value. This seems not happening here. In fact, if I have a look 
on RTC_TR register, the values of RTC_TR subfields exceed their expected values and I didn't get correct update neither for the date (RTC_DR register) nor for the time 
(RTC_TR register) (see capture named "AfterIncre" ).
I may ask if the RTC register representation is in BCD or binary ? In the reference manual, it's mentioned that date and time representation are done using BCD 
format by default but here it seems that representation is done in Binary. Another question is : why hours and date values didn't increment ?
3- Strange values displayed :
I have found another issue with my RTC when I leave my application running for too long. In fact, some strange display figure out (see attached capture named "Strange Display")
What could be the reasons for such behavior ?
PS: For displaying the RTC time and date values , I am using UART connection with Termite 3.1 SW.
I would like to thank you in advance for your support and interest. I am really in urgent need for help because things start to be a little bit confusing for me !

Outcomes