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

How do we know which interrupt resulted in wakeup?

I want my system to sleep for some time, but its waking up and I am unable to understand which interrupt occurred. I want to know which interrupt caused the system to wake up. can u tell me a way to do so?

  • Hello,

    You may try to do something like shown in the snippet below if it's just for debugging.

    static void idle_state_handle(void)
    {
        ret_code_t err_code;
        static int pending_irq = -1;
    
        err_code = nrf_ble_lesc_request_handler();
        APP_ERROR_CHECK(err_code);
    
        if (NRF_LOG_PROCESS() == false)
        {
            
            CRITICAL_REGION_ENTER();
            nrf_pwr_mgmt_run();
            /* Check which interrupt is pending. Will not work properly if there are more than one pending */
            for (uint32_t i = POWER_CLOCK_IRQn; i <= FPU_IRQn; i++)
            {
                if (NVIC_GetPendingIRQ(i))
                {
                    pending_irq = i; // Look up irq number in nrf52.h to find the IRQ source.
                }
            }
            CRITICAL_REGION_EXIT();
    
            if (pending_irq != -1)
            { 
                NRF_LOG_INFO ("Pending IRQ number: %d", pending_irq);
                pending_irq = -1;
            }
    
            
        }
    }

Related