AnsweredAssumed Answered

RTC periodic wake up interrupt fires only once

Question asked by Tyto _Negro_ on Jan 26, 2018

Hi, I'm writing an application with a STM32L051 (32 pin, 64kB ROM).

This application uses the RTC and I wanted to use the RTC periodic auto wake-up feature to update the time display every 60 seconds.

THE PROBLEM:

It looks like the interrupt only happens once at the expected time: after 60 seconds (or any other value I tried)

 

I found an other person having the same problem on a L053 processor using HAL libraries, but no answer or solution was presented. I don't use HAL libraries.

 

My interrupt code looks like this:

 

void RTC_IRQHandler(void)
{
    // when Intr. pending
    if ((EXTI->PR & EXTI_PR_PIF20) == EXTI_PR_PIF20){
        RTC->ISR &= ~(RTC_ISR_WUTWF);  // CLR Wake Up intr. flag
        EXTI->PR |= EXTI_PR_PIF20;     // CLR intr. pending flag (Write 1)

        secs = 0;
        GetTimeDate();
        if ( BTF(KlokStat,klok_on) || BTF(KlokStat,sleep) ){
            DisplayTime(hrs,mins);
        }

        // the 4 lines below were all to test for a solution, to no avail...
        RTC->CR = RTC_CR_WUTE | RTC_CR_WUTIE;
        NVIC_ClearPendingIRQ(RTC_IRQn);   // CLR intr pending register
        EXTI->IMR |= EXTI_IMR_IM20;       // re-enable RTC wake-up intr.
        NVIC_EnableIRQ(RTC_IRQn);         // Re-eanble NVIC for RTC */
    }

}

 

 

The RTC wake-up initialisation code:

 

/* RTC init function */
static void MX_RTC_Init(void)
{
    RTC->WPR = 0xCA; // Unlock Write access for RTC registers
    RTC->WPR = 0x53;
    RTC->CR &= ~RTC_CR_WUTE; // Disable wake up timer to modify it
    // Wait until it is allow to modify wake up reload value
    while((RTC->ISR & RTC_ISR_WUTWF) != RTC_ISR_WUTWF)
    {
    /* add time out here for a robust application */
    }   

    RTC->WUTR = 0x3B; // wake-up period = 60 sec.  0x3B=59

 

    // enable WU tmr, WU tmr Intr. and WU clk =1Hz
    RTC->CR = RTC_CR_WUTE | RTC_CR_WUTIE | RTC_CR_WUCKSEL_2;

    RTC->WPR = 0xFE;  // write protect/lock again
    RTC->WPR = 0x64;

    EXTI->RTSR |= EXTI_RTSR_RT20;  // trigger on rising edge
    // EXTI->FTSR |= EXTI_FTSR_FT20;  // no trigger on falling edge

    EXTI->IMR |= EXTI_IMR_IM20;   // enable RTC wake-up intr. going through EXTI 20 line to NVIC
    //EXTI->EMR |= EXTI_IMR_IM20;   // enable RTC wake-up event necessary?????????


    NVIC_EnableIRQ(RTC_IRQn);     // Configure NVIC for RTC
    NVIC_SetPriority(RTC_IRQn,2); //  Set priority for RTC (=2, low priority)


}

 

My application does *not* sleep, so no real 'wake up' things, I just want to use the interrupt routine to update the clock.

I'm also confused by the interrupt/event thing, but enabling the EXTI event does not make any difference.

 

Any help or tips are highly appreciated.

 

Thanks, Tom

Outcomes