2017-08-02 02:33 PM
I'm struggling to initialize the RTC on an STM8L051F3 microcontroller. I've used the exact code below on an STM8L151K6 microcontroller with no issues. The code hangs waiting for the LSI clock to be ready. Interrupts are disabled before calling the initialize function. Any ideas on what could be wrong?
void RTC_Initialize(void)
{ // configures the RTC (Low Speed Internal RC is 38 kHz) CLK_RTCClockConfig(CLK_RTCCLKSource_LSI, CLK_RTCCLKDiv_1); // wait for LSI clock to be ready while(CLK_GetFlagStatus(CLK_FLAG_LSIRDY) == RESET); <------CODE HANGS HERE CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE); RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div16); RTC_ITConfig(RTC_IT_WUT, ENABLE);2017-08-03 12:40 AM
Hello,
It's my understanding that the LSI clock is always on because it's used for the SWIM functionality? If it isn't then naturally it needs switching on and routing to the RTC with the appropriate dividers set. I'm not too familiar with the peripheral library as I tend to use direct register access but it might be worth seeing what 'CLK_GetFlagStatus' function actually does? Maybe also worth reading about the LSI in the reference manual etc.
Regards,
Ian
2017-08-03 07:35 AM
I created this project in IAR Embedded Workbench for STM8 version 3.10.1 (the latest). It looks like this version of IAR has some issues or there is some different configuration I'm not aware of. Not sure if the issues are just related to debugging or what? I back ported the project to version 2.20.3 of IAR and was able to run the same code above successfully.