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
  • For debugging printf should be OK (in a loop or not), but you should not use it for production, as you will have higher current consumption etc. Also, in general debugging with printf's can be a bad idea, as it will be easy to misunderstand the order of events. Have you for example verified that there is no error check that causes a reset, which would make it seem like the looping is constant, when what might really be happening is that main() is constantly started again after each reset? How have you verified that the CPU does not go to sleep?

Reply
  • For debugging printf should be OK (in a loop or not), but you should not use it for production, as you will have higher current consumption etc. Also, in general debugging with printf's can be a bad idea, as it will be easy to misunderstand the order of events. Have you for example verified that there is no error check that causes a reset, which would make it seem like the looping is constant, when what might really be happening is that main() is constantly started again after each reset? How have you verified that the CPU does not go to sleep?

Children
No Data
Related