cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 RTC problem

omeryaman
Associate II
Posted on December 26, 2014 at 08:39

Hello,

I use an STM32F407 microcontroller for my project that i use RTC on it. The RTC is clocked from LSE. It works normally when the power is on. But when i switch off and on the device, the RTC falls behind the time. To make it clear i switched off and on the device 10 times and the time was nearly 8 seconds back from the time that i first configured. How can i fix this problem?

#lse #rtc #stm32
2 REPLIES 2
Posted on December 26, 2014 at 08:59

I guess one would confirm that the clock is actually ticking during the power off state, and the VBAT is suitably un-interrupted. You might want to look at how you are powering down the device, using SLEEP or STANDBY type operations rather than pulling the power, and how you recover the system and RTC when you restart.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
omeryaman
Associate II
Posted on December 26, 2014 at 11:01

I solved the problem. You are right clive1. It is about system and rtc configuration. I was reconfiguring some parts of rtc and that was changing the time more than half a second. Secondly on SystemClock_Config() function i wrote:

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;

and when i called the function 

HAL_RCC_OscConfig(&RCC_OscInitStruct)

it was always first reseting LSE off and turning it on after. That was changing the time too but not as much as more than half a second. And when i changed function to initialize LSE if only it is not set, the problem was solved.