Skip to main content
Visitor II
August 2, 2017
Question

STM8L051F3 RTC Issue

  • August 2, 2017
  • 1 reply
  • 997 views
Posted on August 02, 2017 at 23:33

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);
    This topic has been closed for replies.

    1 reply

    Visitor II
    August 3, 2017
    Posted on August 03, 2017 at 09:40

    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

    Brian1Author
    Visitor II
    August 3, 2017
    Posted on August 03, 2017 at 14:35

    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.