Question
[stm32f407] Resets RTC and backup registers after power off
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
