Skip to main content
Markus Sierpinski
Associate
February 6, 2017
Question

Problems using Backup Battery on F103C8T6 Controller

  • February 6, 2017
  • 2 replies
  • 1726 views
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
    This topic has been closed for replies.

    2 replies

    waclawek.jan
    Super User
    February 6, 2017
    Posted on February 06, 2017 at 11:24

    Post  code.

    JW

    Markus Sierpinski
    Associate
    February 6, 2017
    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)

      {

      }

    }
    waclawek.jan
    Super User
    February 6, 2017
    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

    Markus Sierpinski
    Associate
    February 6, 2017
    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.