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

how to wake up from IDLE mode using ppi?

Hi

I want to know how to use ppi to wake up CPU from IDLE mode.

I've tried to use timer timeout event for triggering Port Event and wake up CPU, but can't assign NRF_GPIOTE->EVENTS_PORT to ppi channel. nrf_drv_ppi_channel_assign returns NRF_ERROR_INVALID_STATE.

ret_code_t err_code = nrf_drv_timer_init(&timer1, NULL, timer_event_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_timer_extended_compare(&timer1, NRF_TIMER_CC_CHANNEL0, 0xFFFFUL, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false);

nrf_drv_gpiote_init();

err_code = nrf_drv_ppi_init();
APP_ERROR_CHECK(err_code);

// Configure 1st available PPI channel to stop TIMER0 counter on TIMER1 COMPARE[0] match, which is every even number of seconds.
err_code = nrf_drv_ppi_channel_alloc(&ppi_channel1);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_ppi_channel_assign(ppi_channel1,
                                      nrf_drv_timer_event_address_get(&timer1, NRF_TIMER_EVENT_COMPARE0),
                                      NRF_GPIOTE->EVENTS_PORT);
APP_ERROR_CHECK(err_code);

NRF_POWER->TASKS_CONSTLAT = 1;
nrf_drv_timer_enable(&timer1);
while (true)
{
   __WFI();

    if(LED_IS_ON(BSP_LED_0_MASK)){
        LEDS_OFF(BSP_LED_0_MASK);
    } else {
        LEDS_ON(BSP_LED_0_MASK);
    }
    NRF_GPIOTE->EVENTS_PORT = 0;
}

I don't want to configure any pin for GPIOTE, just want to use register.

Thanks!

Parents Reply
  • When you use the driver you should not have to clear the interrupt explicitly (as you do with nrf_timer_event_clear(), as it is done by the driver. You can see this in nrf_drv_timer.c, where the irq_handler() calls nrf_timer_event_clear() just before it calls the event handler you registered with the call to nrf_drv_timer_init().

    I don't understand why your CPU does not go back to sleep, though. Can you double-check?

Children
No Data
Related