2017-02-05 10:16 PM
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.2017-02-06 02:24 AM
Post code.
JW
2017-02-06 02:33 AM
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) { }}2017-02-06 05:28 AM
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
2017-02-06 07:16 AM
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.2017-02-06 04:13 PM
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
2017-02-06 10:30 PM
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
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.
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.
2017-02-07 05:18 AM
Are you inserting the battery while the circuit is powered?
JW
2017-02-07 05:38 AM
No, only in unpowered state
2017-02-07 05:43 AM
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