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

call IRQ handler while waking up the MCU from SYSTEM OFF mode

I am using nRF51822 with SDK 10.0.

I want to configure a GPIO pin which can wake up the MCU from SYSTEM OFF Mode and call its IRQ handler.
Please find below configurations I have done in my code:

// Configure a pin to wake up the MCU and call an IRQ handler
void gpio_configuration(void)
{
    //Usb sense Interrupt Configuration
    nrf_drv_gpiote_in_config_t in_config_1 = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true); // previously we used GPIOTE_CONFIG_IN_SENSE_TOGGLE(false), may have caused to malfunction the code. Didn't checked this yet
    in_config_1.pull = NRF_GPIO_PIN_NOPULL;
    
    err_code = nrf_drv_gpiote_in_init(USB_SENSE, &in_config_1, in_pin_handler_1);
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_gpiote_in_event_enable(USB_SENSE, true);
    
    // config pin to wake up the MCU
    nrf_gpio_cfg_sense_input(USB_SENSE,NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);
}


// I call this function when BLE timeout occurs
uint32_t sd_power_system_off(void)
{
    uint8_t * p_buffer;
    uint32_t buffer_length = 0;
    
    tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
    const uint32_t err_code = power_system_off_req_enc(&(p_buffer[1]), &buffer_length);
    APP_ERROR_CHECK(err_code);
    
    ser_app_power_system_off_set();
    
    //@note: Increment buffer length as internally managed packet type field must be included.
    return ser_sd_transport_cmd_write(p_buffer,
    (++buffer_length),
    NULL);
}

This code can wake up the MCU but it doesn't call its IRQ handler.
But I want to wake up the MCU and call the IRQ handler as soon as an interrupt is generated on this pin.

Is it possible to do so ?

Please guide me.

  • Hello,

    When you go to system off mode, it is like turning off the chip, but you have set this pin as a wakeup source. When the chip wakes up, it will start from the top of main() again, so this event handler is not set up at this point in time, which is why you don't see this interrupt handler. 

    If you want to enter the application in a specific state on wakeup, I suggest you check the state of the pin on startup, to see whether it is high or low, either enter in_pin_handler_1 or not, based on the state of this pin.

    Best Regards,

    Edvin

  • Hi Edvin,

    I got your point and right now implementing it in my project.
    Thanks for your time.

    Apart from this, I have gone through this link.
    Table 9.13 on it have 2 columns named "Wake up" and "ISR Execution".
    Some of its rows have YES-YES for both the columns mentioned above.
    So I am assuming that we can wake the MCU as well call dedicated IRQ Handler, on a single event, if we fulfill all the conditions mentioned in the table.
    Am I missing / misunderstanding some thing here ?

    Can you help me to understand the table and achieve my primary goal using such configurations ?
    It will also help me to understand Cortex-M0, deeply.

    Thank You,
    Maunik Patel

  • If I am not mistaken, your link refers to WFE and WFI, which are system-on mode. System off mode is a much deeper "sleep mode", where the chip is basically turned off. Any interrupt will restart the application from start. 

    I think you are mixing up system-on and system-off sleep modes on the nRF.

  • Ohk Edvin.

    That was my misunderstanding.
    Thanks for clearing it.
    Now I have some what clear picture (as compared to previous state) of these sleep modes.

    Thanks for figuring out my issue.

    Thanks a lot Edvin.  Slight smile

Related