cancel
Showing results for 
Search instead for 
Did you mean: 

RTC calibration when LSI is the RTC clock

trevor23
Associate III
Posted on November 23, 2011 at 02:17

Hi All,

On one of my projects I'm using external watch crystal (32768Hz) as LSE clock to the RTC and all works well. What I now need to do is have the RTC continue to work when the external watch crystal fails. My plan is to detect RTC not moving when CPU is running and then switch to using LSI. However I will need to calibrate the LSI as it has a very high tolerence -- I'm guessing the best way to do this is using the RTC calibration register. SYS clk is from an external 8Mhz crystal so there is a reasonable timing reference. Has anyone got anything they could share/advise for calibrating the RTC when LSI is the RTC clock?

Regards

Trevor
7 REPLIES 7
Posted on November 23, 2011 at 14:13

Interrupt on the RTC 1 second (or whatever your prescale yields), read the core cycle counter at IRQ entry to calibrate source, set a watchdog/equivalent at 1+ seconds to catch failure. You could also monitor the frequency and switch if it wanders out-of-spec.

The STM32F1 series LSI is ~40KHz (39.967), and frankly I didn't find it too stable, or calibrated across temperature.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Chris1
Senior III
Posted on November 23, 2011 at 20:12

Perhaps it would be better to switch the RTC to use HSE/128 if the LSE source should fail.

-Chris
Posted on November 23, 2011 at 20:21

Perhaps it would be better to switch the RTC to use HSE/128 if the LSE source should fail.

It would certainly keep the timebases locked together, but clearly won't help if the part is put in SLEEP or STANDBY.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
trevor23
Associate III
Posted on November 24, 2011 at 10:10

Yes, the RTC needs to run in STANDBY but I could run off HSE/128 while not in STANDBY and the drift (due to temperature etc.) would probably be much better than using LSI (even if calibrated) and I could then use LSI for STANDBY only which does not happen that often is this particular project. Good inputs guys.

arnaud2399
Associate
Posted on December 02, 2011 at 16:29

Hello Trevor,

I need help about the RTC peripheral OF STM32F207

I explain my problem :

Our design is made with  a STM32F207ZG microcontroller and we have some problems with the RTC peripheral.

We have an external 32.768 kHz oscillator (LSE).        

Using the ST library, the initialization of the RTC goes out with ERROR on test of ISR.RSF bit and ISR.INITF bit in

RTC_WaitForSynchro() and RTC_Init(&RTC_InitStructure) functions.

We checked the signal 32 KHz on the MC01 (PA8) pin and it is OK.

If we try with LSI clock source, it is OK : no ERROR.

What happens ? Do you have an idea ?

This is our source code (with RTX kernel) :

int main (void)

{

    SystemInit();

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

    PWR_BackupAccessCmd(ENABLE);       

    RCC_LSEConfig(RCC_LSE_ON);

           …

}

__task void _HORLOGE_Initialiser (void)

{

while (1)

 {           

    while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);

    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

    RCC_RTCCLKCmd(ENABLE);

    RTC_WaitForSynchro();

    // Calendar Configuration 

    RTC_InitStructure.RTC_AsynchPrediv = 0x7F;

    RTC_InitStructure.RTC_SynchPrediv =  0xFF;

    RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;

    RTC_Init(&RTC_InitStructure);

     os_tsk_delete_self ();

    } ;

}

trevor23
Associate III
Posted on December 05, 2011 at 02:39

@arnaud I suggest you start a new thread. I will help if I can.

Regards

Trevor
trevor23
Associate III
Posted on December 05, 2011 at 03:05

I'm having problems switching RTC clock source. You have to reset the backup domain to change clock source however once I change clock souce from LSE to HSE (or LSI) and then try to run from LSE again (including from reset) the code hangs. It sesms to hang on the RTC_WaitForSynchro() following RCC_RTCCLKCmd(ENABLE). If I insert a delay instead of RTC_WaitForSynchro() then it stalls at the next RTC_WaitForLastTask(). Any ideas? After it hangs doing another reset causes it to hang almost immediatly on startup. The only way to recover from this is to remove all power (including VBAT) which resets the backup domain. any ideas appreciated. Cut down code attached.

________________

Attachments :

rtc_problem.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I10A&d=%2Fa%2F0X0000000bh2%2FkKreBr5ZEwjsIWI55GUHinR9DyzA_.mUY5Epy9zA3tw&asPdf=false