cancel
Showing results for 
Search instead for 
Did you mean: 

Problems using Backup Battery on F103C8T6 Controller

Markus Sierpinski
Associate II
Posted on February 06, 2017 at 07:16

Hello,

I designed a circuit that contains a CR2032 Battery for backing up the RTC.

The circuit is shown below.

Without the battery the RTC is running well and an initialize of the RTC is no Problem.

After inserting the battery the controller won't startup anymore.

The program hangs while the RTC is initialize. The function is waiting that the RTC registers will be syncronized. But the RSF Bit will be never set.

If i remove the battery the RSF Bit is immediately set.

I also tried to connect VDD directly to the VBAT Pin, but that results in the same situation, the RTC is not working and the program is hanging.

Is there something that i have forgotten to do?

I already tried to searched the REF manual but without success.0690X00000606FfQAI.png
9 REPLIES 9
Posted on February 06, 2017 at 11:24

Post  code.

JW

Markus Sierpinski
Associate II
Posted on February 06, 2017 at 11:33

Ok, no problem. I will post the RTC Init funciton.

The system is stopping at the read line.

void RTC_Configuration(void)

{

    /* NVIC configuration */

    NVIC_Configuration();

    if (BKP_ReadBackupRegister(BKP_DR1) == CONFIGURATION_RESET)

    {

        /* Enable PWR and BKP clocks */

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

        /* Allow access to BKP Domain */

        PWR_BackupAccessCmd(ENABLE);

        /* Reset Backup Domain */

        BKP_DeInit();

        /* Set Date Information */

        SummerTimeCorrect = MARCH_FLAG_SET;

        BKP_WriteBackupRegister(BKP_DR2,DEFAULT_MONTH);

        BKP_WriteBackupRegister(BKP_DR3,DEFAULT_DAY);

        BKP_WriteBackupRegister(BKP_DR4,DEFAULT_YEAR);

        BKP_WriteBackupRegister(BKP_DR7,SummerTimeCorrect);

        /* Enable LSE */

        RCC_LSEConfig(RCC_LSE_ON);

        /* Wait till LSE is ready */

        while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)

        {}

        /* Select LSE as RTC Clock Source */

        RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

        /* Enable RTC Clock */

        RCC_RTCCLKCmd(ENABLE);

        /* Wait for RTC registers synchronization */

        RTC_WaitForSynchro();

        /* Wait until last write operation on RTC registers has finished */

        RTC_WaitForLastTask();

        /* Enable the RTC Second */

        RTC_ITConfig(RTC_IT_SEC, ENABLE);

        /* Wait until last write operation on RTC registers has finished */

        RTC_WaitForLastTask();

        /* Set RTC prescaler: set RTC period to 1sec */

        RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */

        /* Wait until last write operation on RTC registers has finished */

        RTC_WaitForLastTask();

        SetTime(DEFAULT_HOURS,DEFAULT_MINUTES,DEFAULT_SECONDS);

        BKP_WriteBackupRegister(BKP_DR1, CONFIGURATION_DONE);

    }

    else

    {

        /* Enable PWR and BKP clocks */

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

        /* Allow access to BKP Domain */

        PWR_BackupAccessCmd(ENABLE);

        /* Wait for RTC registers synchronization */

        RTC_WaitForSynchro();

        /* Enable the RTC Second */

        RTC_ITConfig(RTC_IT_SEC, ENABLE);

        /* Wait until last write operation on RTC registers has finished */

        RTC_WaitForLastTask();

    }

    CheckForDaysElapsed();

    SummerTimeCorrect = BKP_ReadBackupRegister(BKP_DR7);

}

/**

  * @brief  Waits until the RTC registers (RTC_CNT, RTC_ALR and RTC_PRL)

  *   are synchronized with RTC APB clock.

  * @note   This function must be called before any read operation after an APB reset

  *   or an APB clock stop.

  * @param  None

  * @retval None

  */

void RTC_WaitForSynchro(void)

{

  /* Clear RSF flag */

  RTC->CRL &= (uint16_t)~RTC_FLAG_RSF;

  /* Loop until RSF flag is set */

  while ((RTC->CRL & RTC_FLAG_RSF) == (uint16_t)RESET)

  {

  }

}
Posted on February 06, 2017 at 13:28

IMO LSE stopped running while BKP_DR1 retained its content.

JW

[EDIT] test this hypothesis by removing battery, shorting VBAT to GND (shorting the 100nF cap on it), replacing battery, trying to run the code

Posted on February 06, 2017 at 15:16

when i remove the battery the RSF of the RTC register is immediatly set.

And the program is working.

Also without a battery and the shorted cap everything is running well. Putting the battery back to its holder will cause the described stop of the program.

I also thinked allready about a not running LSE when the battery is inserted.

I hope that i will get my oscilloscope back tomorrow to test the LSE input.
Posted on February 07, 2017 at 00:13

After putting back the battery it should run through the first leg of the big if() thus should not get to

RTC_WaitForSynchro();

... 

If you use a debugger, you can check whether the LSE is running by looking at the RTC registers (refreshing the view periodically, if there's no autorefresh facility in the debugger). You can also look at the LSE bits in RCC whether they are properly set.

Note that LSE is a low-power circuit and it's easy to choke it with the scope's probe capacitance. If your mcu + DPS allows it, output it onto a MCO pin.

JW

Posted on February 07, 2017 at 06:30

Yeah that's right. If the PCB is complete unpowered the first path of the if statement is executed.

This morning i had the change to measure the crystal with an scope.

If no Battery is inserted the LSE Pin gets the right frequency.

On the upper side OSC32_OUT, the lower one OSC32_IN

0690X0000060673QAA.png0690X00000606G9QAI.png

If i insert the Battery it is not so good. The OSC32_OUT (upper) will get no signal, and the OSC32_IN (lower) will start working when i touch the crystal cap with the probe. 

0690X00000606GEQAY.png0690X00000606GJQAY.png

So i think, that is my problem. At the moment i don't understand, why the battery will have such an effect. Is there a way to solve that behaviour by increasing or decreasing the crystal caps?

Regards and thanks for the help to that point.

Posted on February 07, 2017 at 13:18

Are you inserting the battery while the circuit is powered?

JW

Posted on February 07, 2017 at 13:38

No, only in unpowered state

Posted on February 07, 2017 at 13:43

If you insert battery in unpowered state, it should NOT start to oscillate until the code enables LSE, i.e. until you power it up - regardless of if you touch it or not.

If LSE starts to oscillate without explicitly powering the mcu up, then you have some parasitic power to VDD, either from some external source (debugger?) or from the battery.

JW