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,

    As previously adviced, I have tested out the recommendations from but I stumbled into another issue in the nrf_pwr_mgmt_shutdown(nrf_pwr_mgmt_shutdown_t shutdown_type) in nrf_pwr_mgmt.c  which calls the following;

    /**@brief Function runs the shutdown procedure.
     */
    static void shutdown_process(void)
    {
        NRF_LOG_INFO("Shutdown started. Type %d", m_pwr_mgmt_evt);
        // Executing all callbacks.
        for (/* m_handlers_iter is initialized in nrf_pwr_mgmt_init(). Thanks to that each handler is
                called only once.*/;
             nrf_section_iter_get(&m_handlers_iter) != NULL;
             nrf_section_iter_next(&m_handlers_iter))
        {
            nrf_pwr_mgmt_shutdown_handler_t * p_handler =
                (nrf_pwr_mgmt_shutdown_handler_t *) nrf_section_iter_get(&m_handlers_iter);
            if ((*p_handler)(m_pwr_mgmt_evt))
            {
                NRF_LOG_INFO("SysOff handler 0x%08X => ready", (unsigned int)*p_handler);
            }
            else
            {
                // One of the modules is not ready.
                NRF_LOG_INFO("SysOff handler 0x%08X => blocking", (unsigned int)*p_handler);
                return;
            }
        }
    
        PWR_MGMT_CPU_USAGE_MONITOR_SUMMARY();
        NRF_LOG_INFO("Shutdown complete.");
        NRF_LOG_FINAL_FLUSH();
    
        if ((m_pwr_mgmt_evt == NRF_PWR_MGMT_EVT_PREPARE_RESET)
         || (m_pwr_mgmt_evt == NRF_PWR_MGMT_EVT_PREPARE_DFU))
        {
            NVIC_SystemReset();
        }
        else
        {
            // Enter System OFF.
    #ifdef SOFTDEVICE_PRESENT
            if (nrf_sdh_is_enabled())
            {
                ret_code_t ret_code = sd_power_system_off();
                ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED));
                UNUSED_VARIABLE(ret_code);
    #ifdef DEBUG
                while (true)
                {
                    /* Since the CPU is kept on in an emulated System OFF mode, it is recommended
                     * to add an infinite loop directly after entering System OFF, to prevent
                     * the CPU from executing code that normally should not be executed. */
                    __WFE();
    
                }
                
    #endif
                 
            }
               
    #endif // SOFTDEVICE_PRESENT
            nrf_power_system_off();
        }
    }
     

    The retcode is 2 the ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED)); fails causing the program to crash, being it in Debug as well as in release mode. I also tried the sd_power_system_off() but it fails too with the retcode = 4095. 

    Could someone have a solution to this ? 


    Thanks.

Reply
  • Hello,

    As previously adviced, I have tested out the recommendations from but I stumbled into another issue in the nrf_pwr_mgmt_shutdown(nrf_pwr_mgmt_shutdown_t shutdown_type) in nrf_pwr_mgmt.c  which calls the following;

    /**@brief Function runs the shutdown procedure.
     */
    static void shutdown_process(void)
    {
        NRF_LOG_INFO("Shutdown started. Type %d", m_pwr_mgmt_evt);
        // Executing all callbacks.
        for (/* m_handlers_iter is initialized in nrf_pwr_mgmt_init(). Thanks to that each handler is
                called only once.*/;
             nrf_section_iter_get(&m_handlers_iter) != NULL;
             nrf_section_iter_next(&m_handlers_iter))
        {
            nrf_pwr_mgmt_shutdown_handler_t * p_handler =
                (nrf_pwr_mgmt_shutdown_handler_t *) nrf_section_iter_get(&m_handlers_iter);
            if ((*p_handler)(m_pwr_mgmt_evt))
            {
                NRF_LOG_INFO("SysOff handler 0x%08X => ready", (unsigned int)*p_handler);
            }
            else
            {
                // One of the modules is not ready.
                NRF_LOG_INFO("SysOff handler 0x%08X => blocking", (unsigned int)*p_handler);
                return;
            }
        }
    
        PWR_MGMT_CPU_USAGE_MONITOR_SUMMARY();
        NRF_LOG_INFO("Shutdown complete.");
        NRF_LOG_FINAL_FLUSH();
    
        if ((m_pwr_mgmt_evt == NRF_PWR_MGMT_EVT_PREPARE_RESET)
         || (m_pwr_mgmt_evt == NRF_PWR_MGMT_EVT_PREPARE_DFU))
        {
            NVIC_SystemReset();
        }
        else
        {
            // Enter System OFF.
    #ifdef SOFTDEVICE_PRESENT
            if (nrf_sdh_is_enabled())
            {
                ret_code_t ret_code = sd_power_system_off();
                ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED));
                UNUSED_VARIABLE(ret_code);
    #ifdef DEBUG
                while (true)
                {
                    /* Since the CPU is kept on in an emulated System OFF mode, it is recommended
                     * to add an infinite loop directly after entering System OFF, to prevent
                     * the CPU from executing code that normally should not be executed. */
                    __WFE();
    
                }
                
    #endif
                 
            }
               
    #endif // SOFTDEVICE_PRESENT
            nrf_power_system_off();
        }
    }
     

    The retcode is 2 the ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED)); fails causing the program to crash, being it in Debug as well as in release mode. I also tried the sd_power_system_off() but it fails too with the retcode = 4095. 

    Could someone have a solution to this ? 


    Thanks.

Children
No Data
Related