cancel
Showing results for 
Search instead for 
Did you mean: 

RTC and surprise power removal

M0NKA
Senior
Posted on December 22, 2012 at 19:12

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

3 REPLIES 3
Posted on December 23, 2012 at 00:06

I am on LSI clock right now.  

 

Well that's your problem right there, the battery only runs the LSE as it uses a lot less power.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on December 23, 2012 at 00:13

RM0090

4.1.2 Battery backup domain

 

Backup domain description

 

To retain the content of the RTC backup registers, backup SRAM, and supply the RTC when VDD is turned off, VBAT pin can be connected to an optional standby voltage supplied by a battery or by another source.

 

To allow the RTC to operate even when the main digital supply (VDD) is turned off, the VBAT pin powers the following blocks:

 

�? The RTC

 

�? The LSE oscillator

 

�? The backup SRAM when the low power backup regulator is enabled

 

�? PC13 to PC15 I/Os, plus PI8 I/O (when available)

 

The switch to the VBAT supply is controlled by the power-down reset embedded in the Reset block.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
M0NKA
Senior
Posted on December 23, 2012 at 11:52

Thanks clive,

My bad again, reading but not comprehending. And i didn't test because the

oscillator i bought will not start (12.5pF loading capacitance), but read too

late about the limitation.

One final question on the subject. Do you think is ok to run the RTC on HSE clock

during normal operation, to minimize the noise floor, but before going to stop mode

switch to LSE ? This clock switching will maybe make the clock to loose sync for

a while and loose precision ? Also in this case i will still have the surprise power

removal problem i guess.

BR, Chris

Update: All works now, it seems i have bought the 6pF version of the oscillator,

but the two extra capacitors values are very critical - 6.8pF were no go, extra

1pF in parallel made it work (8pF required by the pdf).