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

nrf51822- GPIOTE interrupt for wakeup with softdevice

I am trying to wake my processor from sleep after issuing the sd_app_evt_wait(); Using an interrupt on an external RTC chip, I send interrupt pulses to the nRF at 1Hz. At startup, I have the softdevice advertise for 5 seconds then perform power management(based off the HRM example) by shutting down the spi and twi busses and the application timers for the simulated data (again, all in the HRM example). So what I see is that the LED08 in the RTC interrupt handler toggles at 1Hz as expected. Also expected is the LED1 toggling as other timer interrupts are firing, and releasing the block of sd_app_evt_wait() within power_manage().

When advertising expires, LED1 stops toggling, but LED8 (within the interrupt handler) keeps toggling. It almost seems that there is no signal to unblock sd_app_evt_wait();. Clearly I am getting interrupts, but it doesnt seem to be configured correctly to unblock sd_app_evt_wait(); in main.

Can anyone point me in the right direction?

Appropiate parts of my code is as follows:

void rtc_int_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    nrf_gpio_pin_toggle(LED08);
}

void interrupt_pin_init(void) // put after nrf_drv_gpiote_init() in main
{
    ret_code_t err_code;
    err_code = nrf_drv_gpiote_init();
    //APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(false);
    in_config.pull = NRF_GPIO_PIN_PULLUP;

    err_code = nrf_drv_gpiote_in_init(RTC_INT, &in_config, rtc_int_handler);
    APP_ERROR_CHECK(err_code);
    nrf_drv_gpiote_in_event_enable(RTC_INT, true);

}

static void power_manage(void)
{
    uint32_t err_code = sd_app_evt_wait();
    APP_ERROR_CHECK(err_code);
}


int main(void)
{
    uint32_t err_code;
    bool erase_bonds;

    //set lf clock to use 32Khz xtal
    NRF_CLOCK->TASKS_LFCLKSTOP = 1;
    NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal;
    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    while(!NRF_CLOCK->EVENTS_LFCLKSTARTED); //wait for LFCLOCK start

    //set HF clock to use 32MHz xtal
    NRF_CLOCK->XTALFREQ = 0x00;
    NRF_CLOCK->TASKS_HFCLKSTART = 1;
    while(!NRF_CLOCK->EVENTS_HFCLKSTARTED);  //wait for our HFCLOCK

    // Initialize.
    app_trace_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    ble_stack_init();
    device_manager_init(erase_bonds);

    db_discovery_init();
    gap_params_init();
    advertising_init();
    services_init();
    sensor_simulator_init();
    conn_params_init();

    gpio_pin_init();

    err_code = nrf_drv_spi_init(&m_spi_master, &spi0_config, spi_master_event_handler);
    APP_ERROR_CHECK(err_code);

    external_spi_RTC_init();

    // Start execution.
    nrf_delay_ms(2000);
    interrupt_pin_init();

    application_timers_start();

    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);

    // Enter main loop.
    for (;;)
    {
        power_manage();
        nrf_gpio_pin_toggle(LED01);

    }
}
Parents
  • FormerMember
    0 FormerMember

    In rtc_int_handler(), the gpiote event is not being cleared. Check if it changes anything if you clear the event using nrf_gpiote_event_clear(..).

    Update 01.11.2016: The RTC will continue to run when the chip is put in system ON unless the RTC is explicitly turned off. The current consumption will still be low because the RTC uses LFCLK.

  • Well, LED08 is linked to an external interrupt which gives me an interrupt pulse at 1HZ. I was expecting power_manage() to block execution until the processor received an interrupt of some sort. When the SoftDevice is advertising, it seems to unblock at a fairly high rate, as indicated by the toggling of LED1.

    I Expected that when softdevice stopped advertising at the expiration of the advertising interval, that the power_manage() function would unblock at the same rate as the external interrupt, thus having both LED01 and LED08 flash at the same rate ( if out of phase).

    But they currently do not. LED01 keeps flashing at a higher rate ( it seems to be ~10Hz) even after the advertising timer expires.

    And I am certain I have not entered a connected state.

    Is there a way to see if the softdevice is in something other than an idle state?

Reply
  • Well, LED08 is linked to an external interrupt which gives me an interrupt pulse at 1HZ. I was expecting power_manage() to block execution until the processor received an interrupt of some sort. When the SoftDevice is advertising, it seems to unblock at a fairly high rate, as indicated by the toggling of LED1.

    I Expected that when softdevice stopped advertising at the expiration of the advertising interval, that the power_manage() function would unblock at the same rate as the external interrupt, thus having both LED01 and LED08 flash at the same rate ( if out of phase).

    But they currently do not. LED01 keeps flashing at a higher rate ( it seems to be ~10Hz) even after the advertising timer expires.

    And I am certain I have not entered a connected state.

    Is there a way to see if the softdevice is in something other than an idle state?

Children
No Data
Related