This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

RTC interrupt does not wake up nRF52

I am having issues waking up nRF52 with s132 using the RTC interrupt. The same code is used on nRF51 with s130 and does not show this behavior.

The RTC is configured and the interrupts are fired and handled as expected every 10ms. The Softdefice is running but no advertising is enabled. The RTC configuration looks like:

NRF_RTC1->PRESCALER = 0;
NRF_RTC1->CC[0] = 32768 / 100;
NRF_RTC1->INTENCLR = 0xffffffffUL;
NRF_RTC1->INTENSET = (RTC_INTENSET_COMPARE0_Set << RTC_INTENSET_COMPARE0_Pos);
NRF_RTC1->TASKS_START = 1;

result = sd_nvic_ClearPendingIRQ (RTC1_IRQn);
ASSERT (result == NRF_SUCCESS);
result = sd_nvic_SetPriority (RTC1_IRQn,NRF_APP_PRIORITY_LOW);
ASSERT (result == NRF_SUCCESS);
result = sd_nvic_EnableIRQ (RTC1_IRQn);
ASSERT (result == NRF_SUCCESS);

The problem occures when sending the nRF52 into sleep mode with:

result = sd_app_evt_wait();

Compared to the nRF51 the nRF52 is not woken up by the RTC interrupt. Setting the Send Event on Pending bit in the System Control Register fixes the problem but it should not be necessary to set it:

SCB->SCR |= SCB_SCR_SEVONPEND_Msk;

Why is it necessary to set the the bit on nRF52? The interrupt for RTC is enabled and fired when the CPU is not sleeping. Did I miss a configuration on nRF52 which is not needed on nRF51?

  • Can you post the code snippet where you handle the RTC1_IRQn interrupts? What is the numerical value of NRF_APP_PRIORITY_LOW? The priority levels have changed between nRF51 and 52

  • The IRQ handler for the RTC interrupt:

    void RTC1_IRQHandler (void)
    {
        gu64_timerTicks += NRF_RTC1->COUNTER;
        NRF_RTC1->TASKS_CLEAR = 1;
        NRF_RTC1->EVENTS_COMPARE[0] = 0;
    
        if ( sd_nvic_ClearPendingIRQ (RTC1_IRQn) != NRF_SUCCESS)
        {
            NVIC_ClearPendingIRQ (RTC1_IRQn);
        }
    }
    

    The IRQ priority is defined this way for backward compatibility:

    #define NRF_APP_PRIORITY_LOW (APP_IRQ_PRIORITY_LOW)
    

    Lookin into app_util_Platform.h the priority of APP_IRQ_PRIORITY_LOW for nRF51 is 3 and for nRF52 it is 6. I also tried to set the IRQ priortiy for nRF52 to 3, but it did not solve the problem.

  • Hi

    It is also possible to configure the RTC on nRF52 with help of the nrf_drv_rtc driver. There is an example here, the saadc_low_power, that uses the nrf_drv_rtc driver and the RTC interrupt, which is working properly. Look at the rtc_config and rtc_handler functions in the example. When looking at the driver functions, I don't quickly see any specific nRF52 code there. So I would recommend to use the driver, or otherwise mimic what the driver does in order to have this working.

Related