9 years, 8 months ago.

RTC not keeping time with Vbat powered and crystals fitted.

With 8MHz and 32KHz crystals, capacitors and links fitted and a separate supply to Vbat, the RTC resets to zero on power cycle. It also zero's when the reset button is pressed. Both crystals are running when powered and the 32KHz crystal runs when powered down using Vbat to supply the RTC. Any ideas where the RTC register reset function on start up is in the library?

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32F030R8T6 microcontroller.

Okay, commenting some and all out all the RCC_BackupResetCmd functions had no effect.

What I have discovered is that RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); Enable PWR clock in the rtc_api.c resets the RTC time registers. I have a work around by simply adding a condition to call this if the register: RTC->ISR == 0x07 (Vdd and Vbat power down cycle reset value). If Vbat is powered and a hardware reset or Vdd power down occurs the RTC->ISR value remains at 0x37, I assume indicating the RTC registers have been initialised. However I can not set the time now.

posted by Paul Staron 25 Aug 2014

I am having the same problem, with a Nucleo L152, did you ever solve the problem such that connecting a battery keeps the time between resets and allows you to set time?

posted by Andy Bradley 31 Jan 2015

1 Answer

9 years, 8 months ago.

The RTC init code is responsible by calling:

RCC_BackupResetCmd(ENABLE); 
RCC_BackupResetCmd(DISABLE);

Either that shouldn't be called (have my doubts if it is actually required), or it should check if the RTC is already running to determine if it should init the RTC.

I have tried disabling these parts (commented out the whole function) in the rcc.c file ( starting at line 1304) with no effect. I think the RTC registers are reset somewhere else in the start up process perhaps in the RTC start up.

posted by Paul Staron 25 Aug 2014

Does the RTC still startup with those disabled? They are called in https://mbed.org/users/mbed_official/code/mbed-src/file/ec1b66a3d094/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/rtc_api.c, but thats done by calling those functions, commenting them out should make sure nothing is actually done.

posted by Erik - 25 Aug 2014

I have fixed the problem only for F401RE & F411RE mbed board.
If a battery back up HW is well equipped, RTC can run over power off and reset timing.
But for F080 and L152, I still need to fight with them because VBAT pin is not available those CPU's.
Please refer follows.
/users/kenjiArai/notebook/nucleo-series-rtc-control-under-power-onoff-and-re/

posted by Kenji Arai 07 Feb 2015