AnsweredAssumed Answered

RTC and surprise power removal

Question asked by K A on Dec 22, 2012
Latest reply on Dec 23, 2012 by K A
Hi,

I just added backup battery to the F407 discovery board. All seem to work ok, the RTC counts while the CPU is on and in Stop mode as well. But if i remove the power all together the last RTC value is preserved by the battery, but no update on the RTC is done. Reading the pdf few times and all possible posts on the forum, i am more confused. Maybe my RTC init is bad ?

RTC_InitTypeDef     RTC_InitStructure;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

// Allow access to BKP Domain
PWR_BackupAccessCmd(ENABLE);

#ifdef RTC_CLOCK_SOURCE_LSI

    // Enable the LSI OSC
    RCC_LSICmd(ENABLE);

    // Wait till LSI is ready
    while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET);

    // Select the RTC Clock Source
    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);

    RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
    RTC_InitStructure.RTC_SynchPrediv  = 0xFF;

#endif
#ifdef RTC_CLOCK_SOURCE_LSE

    // Enable the LSE OSC
    RCC_LSEConfig(RCC_LSE_ON);

    // Wait till LSR is ready
    while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);

    // Select the RTC Clock Source
    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

    RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
    RTC_InitStructure.RTC_SynchPrediv =  0xFF;

#endif

    // Enable the RTC Clock
    RCC_RTCCLKCmd(ENABLE);

    // Wait for RTC APB registers synchronisation (needed after start-up from Reset)
    RTC_WaitForSynchro();

    // Set the RTC time base to 1s
    RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;

    if (RTC_Init(&RTC_InitStructure) == ERROR)
    {
        // User can add here some code to deal with this error
        //while(1);
    }

    // Enable BKPRAM Clock
    //RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE);

    // Enable the Backup SRAM low power Regulator
    //PWR_BackupRegulatorCmd(ENABLE);

    // Wait until the Backup SRAM low power Regulator is ready
    //while(PWR_GetFlagStatus(PWR_FLAG_BRR) == RESET);

I am on LSI clock right now.  

Regards, Chris

Outcomes