Skip to main content
EKoro
Associate
September 6, 2018
Question

[stm32f407] Resets RTC and backup registers after power off

  • September 6, 2018
  • 4 replies
  • 1218 views

Good day. A strange problem. After turning off the power, the backup registers and the real time clock are reset.

Could it be that I messed up at initialization, or something that I missed?

void RTC_init( void )
{
 RTC_InitTypeDef rtc;
 RTC_InitTypeDef RTC_InitStructure;
 RTC_TimeTypeDef RTC_TimeStructure;
 RTC_DateTypeDef RTC_DateStructure;
 
 RCC_APB1PeriphClockCmd( RCC_APB1Periph_PWR, ENABLE );
 RCC_AHB1PeriphClockLPModeCmd ( RCC_AHB1Periph_BKPSRAM, ENABLE );
 PWR_BackupAccessCmd(ENABLE);
 
 if (RTC_ReadBackupRegister(RTC_BKP_DR0) != FIRST_DATA) {
 
 RCC_LSEConfig( RCC_LSE_ON );
 while ( RCC_GetFlagStatus( RCC_FLAG_LSERDY ) == RESET );
 
 RCC_RTCCLKConfig( RCC_RTCCLKSource_LSE );
 RCC_RTCCLKCmd( ENABLE );
 
 RTC_WaitForSynchro();
 
 
 RCC_DeInit();
 RTC_InitTypeDef rtc;
 RTC_StructInit(&rtc);
 rtc.RTC_HourFormat = RTC_HourFormat_24;
 rtc.RTC_AsynchPrediv = 127;
 rtc.RTC_SynchPrediv = 249;
 RTC_Init(&rtc);
 
 RTC_TimeStructure.RTC_Hours = 0;
 RTC_TimeStructure.RTC_Minutes = 0;
 RTC_TimeStructure.RTC_Seconds = 0;
 RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
 RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure);
 
 RTC_DateStructure.RTC_Date = 1;
 RTC_DateStructure.RTC_Month = RTC_Month_January;
 RTC_DateStructure.RTC_WeekDay = RTC_Weekday_Monday;
 RTC_DateStructure.RTC_Year = 0;
 RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure);
 
 }
 RTC_WriteBackupRegister(RTC_BKP_DR0, FIRST_DATA);
}

The clock source is LSE. Vbat is connected through an ionistor. Ionistor connection diagram

0690X000006BzQVQA0.jpg

This topic has been closed for replies.

4 replies

LMI2
Senior III
September 6, 2018

The RTC HW or its drivers are buggy, but lets wait what the real experts say.

waclawek.jan
Super User
September 6, 2018

And what does the debugger say about content of RTC_BKP_DR0?

JW

EKoro
EKoroAuthor
Associate
September 7, 2018

@Community member​ 

After reset, RTC_BKP_DR0 = 0

If reboot without turning off the power, then RTC_BKP_DR0 = FIRST_DATA

#define FIRST_DATA 0x43B1 

waclawek.jan
Super User
September 7, 2018

Verify that the battery is connected to the VBAT pin of the STM32 (i.e. that there is no bad solder joint).

Measure the voltage on the VBAT pin when supply voltage (VDD) is removed.

Also verify that VDDA is connected to supply voltage and VSSA is connected to ground.

Also, you do not set some pin as TAMPER, do you?

What is "ionistor"? [EDIT] Okay I looked it up, it's supercap. https://ru.wikipedia.org/wiki/%D0%98%D0%BE%D0%BD%D0%B8%D1%81%D1%82%D0%BE%D1%80 It appears that it's called so only in the russian language group, although it's a very apt name for this sort of parts. [/EDIT]

JW