Skip to main content
emilio
Associate III
March 3, 2014
Question

Using Standby Mode with the RTC

  • March 3, 2014
  • 18 replies
  • 3307 views
Posted on March 03, 2014 at 17:40

Hello everybody.

I am developing some test firmwares on a STM32F103 based board.

After some working programs using the sleep mode, now I need to do some experience with the much more powerful standby mode.

I need to set a fixed timer using the RTC in order to wake up the system periodically to perform some tasks. I want to use the RTC, no external interrupts.

Can anybody help me with a code example?

Thanks in advance
    This topic has been closed for replies.

    18 replies

    chen
    Associate II
    March 3, 2014
    Posted on March 03, 2014 at 18:03

    Hi

    Here is a link to the 'Standard Perpheral Drivers' for the STM32F103 series of processors.

    http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/PF257890

    It might have some example code for you to look at.

    stm322399
    Senior
    March 3, 2014
    Posted on March 03, 2014 at 18:03

    Emilio,

    help yourself with this code i used in STM32L150 (beware of possible differences with your F103):

    RTC_WakeUpCmd(DISABLE);
    RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div2);
    RTC_SetWakeUpCounter(period/2);
    RTC_ITConfig(RTC_IT_WUT,ENABLE);
    RTC_WakeUpCmd(ENABLE);

    emilio
    emilioAuthor
    Associate III
    March 3, 2014
    Posted on March 03, 2014 at 19:05

    I would like to use the RTC alarm to wake up from standby mode. Unfortunately I don't have a LSE on my board.

    Where can I find some examples about the alarm configuration and use?
    Tesla DeLorean
    Guru
    March 3, 2014
    Posted on March 03, 2014 at 19:22

    Unfortunately I don't have a LSE on my board.

    That's going to represent a significant problem when the power domain the LSI is in goes down, isn't it?
    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    emilio
    emilioAuthor
    Associate III
    March 4, 2014
    Posted on March 04, 2014 at 14:38

    So I cannot use the standby mode without using an EXTI line?

    stm322399
    Senior
    March 4, 2014
    Posted on March 04, 2014 at 14:59

    You can wake up the CPU with RTC clocked by LSI.

    LSI can run in stand-by mode if you configure it to do so, and as long as Vdd is powered.

    the manual says:

    40 kHz low speed internal RC (LSI RC) which drives the independent watchdog and optionally the RTC used for Auto-wakeup from Stop/Standby mode.

    emilio
    emilioAuthor
    Associate III
    March 5, 2014
    Posted on March 05, 2014 at 10:34

    Thanks for answering.

    Can you advise me about what code I have to use in order to configure the LSI properly?

    I am trying but I have some problems.

    emilio
    emilioAuthor
    Associate III
    March 5, 2014
    Posted on March 05, 2014 at 11:21

    I would like using the LSI for auto wake-up my system from standby but I am not finding any example code and I am not very good using the RTC, I usually use ''normal'' timer.

    stm322399
    Senior
    March 5, 2014
    Posted on March 05, 2014 at 12:14

    Have you got a look to the PWR/STDBY example ?

    It looks very close to what you try to do, excepted that you have to configure LSI instead of LSE.

    The Ref manual says:

    To wakeup from Stop mode with an RTC alarm event, it is necessary to:

    �? Configure the EXTI Line 17 to be sensitive to rising edge

    �? Configure the RTC to generate the RTC alarm

    To wakeup from Standby mode, there is no need to configure the EXTI Line 17.

    emilio
    emilioAuthor
    Associate III
    March 6, 2014
    Posted on March 06, 2014 at 10:42

    I am starting from examples but my firmware is not working.

    I am using the following code to configure the RTC Alarm with the LSI in order to have an interrupt 3 second after the WFI instruction, but the RTC_AlarmIRQHandler doesn't play

    NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;                     

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 13;               

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init( &NVIC_InitStructure );

     

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

    PWR_BackupAccessCmd(ENABLE);

    BKP_DeInit();

    RCC_LSICmd(ENABLE); /* Enable LSI */

    while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET); /* Wait till LSI is ready */

    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);

    RCC_RTCCLKCmd(ENABLE);

    RTC_WaitForSynchro();

    RTC_SetPrescaler(32767);

    RTC_WaitForLastTask();  

    RTC_ITConfig(RTC_IT_ALR, ENABLE);

    RTC_WaitForLastTask();       RTC_ClearFlag(RTC_FLAG_SEC);

    while(RTC_GetFlagStatus(RTC_FLAG_SEC)==RESET);

          

    RTC_SetAlarm(RTC_GetCounter()+3);

    RTC_WaitForLastTask();

    __WFI();