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

Setting nRF52840 to deep sleep (sytem-off) and waking up on dedicated pin interrupt.

Hello All,

I am working on the development of a  product based on the nFR52840 SoC (SDK 16 and softdevice 14) and have several pheripherals connected to the chip, one of which is the nRF9160 SiP. My question is a 2 parter;

1. I can software shutdown the other pheripherals, but I couldn't figure out how to do this for the nRF9160, could It be done? If yes, please how do I proceed (software shutdown)?

2. I had a  look at some similar cases and explanations point towards the ble_pheripheral_templetate which advertises for 3 min and goes into deep sleep if no connection is made. Then it should wake up on pressing btn1.

   But it wakes up when any btn in pressed or NFC is detected. How could I implement this concept for my device while sensing only 1 choosen gpio pin as interrupt for waking up the nrf52840 chip ?

Thanks in advance for you time and response.

Parents
  • Hello Martin,

    thanks for you reply. I would take a look and try to implement as adviced. I will update the ticket with the outcome I get.

  • Hello

    I have been trying out power management library and I used the nrf_gpio_cfg_sense_input(pin Num, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW) to assigne the wakeup pin. This works well in the  "Power Management " sample" but when I port it to my firmware and try to use btn 4 to put the device to sleep, it crashes with the following error: 

    <info> app: Power management allowed to reset to DFU mode.
    <error> app: ERROR 3735928559 [Unknown error code] at C:\...\components\libraries\pwr_mgmt\nrf_pwr_mgmt.c:418
    PC at: 0x0003DC77
    <error> app: End of error report

     ret_code_t ret_code = sd_power_system_off();  return 2 from nrf_pwr_mgmt.c line 417, even though the softdevice is enabled.

    I could not trace back to the problem, do you have any idea on why this occurs and the solution to it? 

    Thanks again .

    here is the shutdown handler:

    /**@brief Handler for shutdown preparation.
    */
    bool shutdown_handler(nrf_pwr_mgmt_evt_t event)
    {
    uint32_t err_code;
    
    if (m_is_ready == false)
    {
    m_sysoff_started = true;
    return false;
    }
    
    switch (event)
    {
    case NRF_PWR_MGMT_EVT_PREPARE_SYSOFF:
    NRF_LOG_INFO("NRF_PWR_MGMT_EVT_PREPARE_SYSOFF");
    err_code = bsp_buttons_disable();
    APP_ERROR_CHECK(err_code);
    break;
    
    case NRF_PWR_MGMT_EVT_PREPARE_WAKEUP:
    NRF_LOG_INFO("NRF_PWR_MGMT_EVT_PREPARE_WAKEUP");
    err_code = bsp_buttons_disable();
    // Suppress NRF_ERROR_NOT_SUPPORTED return code.
    UNUSED_VARIABLE(err_code);
    
    // err_code = bsp_wakeup_button_enable(BTN_ID_WAKEUP);
    // // Suppress NRF_ERROR_NOT_SUPPORTED return code.
    // UNUSED_VARIABLE(err_code);
    
    nrf_gpio_cfg_sense_input(24, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    
    err_code = bsp_nfc_sleep_mode_prepare();
    // Suppress NRF_ERROR_NOT_SUPPORTED return code.
    UNUSED_VARIABLE(err_code);
    break;
    
    case NRF_PWR_MGMT_EVT_PREPARE_DFU:
    NRF_LOG_ERROR("Entering DFU is not supported by this example.");
    APP_ERROR_HANDLER(NRF_ERROR_API_NOT_IMPLEMENTED);
    break;
    
    case NRF_PWR_MGMT_EVT_PREPARE_RESET:
    NRF_LOG_INFO("NRF_PWR_MGMT_EVT_PREPARE_RESET");
    break;
    }
    
    err_code = app_timer_stop_all();
    APP_ERROR_CHECK(err_code);
    
    return true;
    }
    
    /**@brief Register application shutdown handler with priority 0. */
    NRF_PWR_MGMT_HANDLER_REGISTER(shutdown_handler, 0);

Reply
  • Hello

    I have been trying out power management library and I used the nrf_gpio_cfg_sense_input(pin Num, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW) to assigne the wakeup pin. This works well in the  "Power Management " sample" but when I port it to my firmware and try to use btn 4 to put the device to sleep, it crashes with the following error: 

    <info> app: Power management allowed to reset to DFU mode.
    <error> app: ERROR 3735928559 [Unknown error code] at C:\...\components\libraries\pwr_mgmt\nrf_pwr_mgmt.c:418
    PC at: 0x0003DC77
    <error> app: End of error report

     ret_code_t ret_code = sd_power_system_off();  return 2 from nrf_pwr_mgmt.c line 417, even though the softdevice is enabled.

    I could not trace back to the problem, do you have any idea on why this occurs and the solution to it? 

    Thanks again .

    here is the shutdown handler:

    /**@brief Handler for shutdown preparation.
    */
    bool shutdown_handler(nrf_pwr_mgmt_evt_t event)
    {
    uint32_t err_code;
    
    if (m_is_ready == false)
    {
    m_sysoff_started = true;
    return false;
    }
    
    switch (event)
    {
    case NRF_PWR_MGMT_EVT_PREPARE_SYSOFF:
    NRF_LOG_INFO("NRF_PWR_MGMT_EVT_PREPARE_SYSOFF");
    err_code = bsp_buttons_disable();
    APP_ERROR_CHECK(err_code);
    break;
    
    case NRF_PWR_MGMT_EVT_PREPARE_WAKEUP:
    NRF_LOG_INFO("NRF_PWR_MGMT_EVT_PREPARE_WAKEUP");
    err_code = bsp_buttons_disable();
    // Suppress NRF_ERROR_NOT_SUPPORTED return code.
    UNUSED_VARIABLE(err_code);
    
    // err_code = bsp_wakeup_button_enable(BTN_ID_WAKEUP);
    // // Suppress NRF_ERROR_NOT_SUPPORTED return code.
    // UNUSED_VARIABLE(err_code);
    
    nrf_gpio_cfg_sense_input(24, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    
    err_code = bsp_nfc_sleep_mode_prepare();
    // Suppress NRF_ERROR_NOT_SUPPORTED return code.
    UNUSED_VARIABLE(err_code);
    break;
    
    case NRF_PWR_MGMT_EVT_PREPARE_DFU:
    NRF_LOG_ERROR("Entering DFU is not supported by this example.");
    APP_ERROR_HANDLER(NRF_ERROR_API_NOT_IMPLEMENTED);
    break;
    
    case NRF_PWR_MGMT_EVT_PREPARE_RESET:
    NRF_LOG_INFO("NRF_PWR_MGMT_EVT_PREPARE_RESET");
    break;
    }
    
    err_code = app_timer_stop_all();
    APP_ERROR_CHECK(err_code);
    
    return true;
    }
    
    /**@brief Register application shutdown handler with priority 0. */
    NRF_PWR_MGMT_HANDLER_REGISTER(shutdown_handler, 0);

Children
No Data
Related