cancel
Showing results for 
Search instead for 
Did you mean: 

RTC clock not starting consistenly

TConl.1
Associate II

Hi everyone, I'm using the STM8L152R8 Nucleo board and trying to get the RTC running on the LSE clock. It works but only inconsistenly, about 2/3 runs error out in the RTC_EnterInitMode function of the SPL the below line. RTC_EnterInitMode is called from RTC_Init which I call in my setup.

  if ((RTC->ISR1 & RTC_ISR1_INITF) == RESET)
  {
    status = ERROR;
  }

My setup is

while (CLK_GetFlagStatus(CLK_FLAG_LSERDY) == RESET); 
/* wait for 1 second for the LSE Stabilisation */
 
/* Select LSE  as RTC clock source */
CLK_RTCClockConfig(CLK_RTCCLKSource_LSE, CLK_RTCCLKDiv_1); 
CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE); 
 
RTC_InitTypeDef RTC_InitStr; 
RTC_InitStr.RTC_HourFormat = RTC_HourFormat_24; 
RTC_InitStr.RTC_AsynchPrediv = 0x7F; 
RTC_InitStr.RTC_SynchPrediv = 0x00FF; 
RTC_Init(&RTC_InitStr); 
 
 //setup calender
	

I can see from the registers that the LSE is setup correctly however the RTC is not setup at all.

Can anyone suggest what is happening here?

Thanks!

1 REPLY 1
TConl.1
Associate II

I removed the timeout which has solved the issue though I'm not certain why.

From the manauls init steps :

' Poll INITF bit of in the RTC_ISR register. The initialization phase mode is entered when INITF is set to 1. It takes around 2 RTCCLK clock cycles for synchronization purposes.'

The timeout was '0xFFFF' which should be more than enough time for 2 RTC clock cycles with LSE at 32.768 kHz and HSI at 16 MHz.

If anyone can shed some light on this it would be appreciated. Thanks