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

nrf52832 sleep mode from android app

I am currently looking at how to put the nrf52 development board to sleep (and wake up) by sending a command from an android application (with SDK v15.2).

I have been experimenting with the nrfBlinky app and wanted to know if anyone has some advice on how one would go about doing this.

I have searched the forums but couldn't find a similar question although there are posts about calling __WFE() to put the board in low power mode from the firmware (or calling an event like sd_app_evt_wait()). I did read there are two sleep mode for this board a SYSTEM ON and SYSTEM OFF mode. I am not certain which mode suits the use case best, although I assume we would want the SYSTEM ON mode as the app would need to send an event to wake it up. Although I wouldn't be against a SYSTEM OFF mode where the reset button would need to be pressed to wake it up (so just sending a "put to sleep" command from the app). 

Any advice would be much appreciated.

  • mialo_5 said:
    Therefore based on your reply for Question 1, you mention looking at the ble_uart example which uses a softdevice which I don't believe I am using. Is this then the only way to get the device to sleep in a System OFF mode and why my test didn't work or have I missed something? 

    Why does it not work? Have you tried to debug and see what error messages you get?

    mialo_5 said:
    Therefore based on your reply for Question 1, you mention looking at the ble_uart example which uses a softdevice which I don't believe I am using. Is this then the only way to get the device to sleep in a System OFF mode and why my test didn't work or have I missed something? 

    If you want control your device from an android app you need a SoftDevice (which handles all low level BLE activity). The reason I recommended you the ble_app_uart example is because it is a quite simple example which uses the SoftDevice.

  • Thanks for your help although I don't believe I am getting to the answer I'm looking for.

    Maybe if I rephrase the question as follows:

    I am using the nrfBlinky Android app with an nrf52832. I would like to press a button on the dev board to put the board into a system off (sd_power_system_off() or nrf_pwr_mgmt._shutdown()) sleep mode where I can only recover by pressing RESET button on the board.

    If I create a static variable "m_is_sleep_mode" to store if BSP_BUTTON_1 is pressed and check that it is true in the main function (in the for(;;) loop I assume), see code snippet, the board seems to perform a reset (the connection drops and comes back up immediately) but has not gone into a power down mode.

    Thoughts this time?

    static void button_event_handler(uint8_t pin_no, uint8_t button_action)
    {
        ret_code_t err_code;
    
        switch (pin_no)
        {
            case LEDBUTTON_BUTTON:
                NRF_LOG_INFO("Send button state change.");
                err_code = ble_lbs_on_button_change(m_conn_handle, &m_lbs, button_action);
                if (err_code != NRF_SUCCESS &&
                    err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
                    err_code != NRF_ERROR_INVALID_STATE &&
                    err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
                {
                    APP_ERROR_CHECK(err_code);
                }
                break;
    
            case SLEEPBUTTON_BUTTON:
                m_is_sleep_mode = true;
                break;
    
            default:
                APP_ERROR_HANDLER(pin_no);
                break;
        }
    }

    static void buttons_init(void)
    {
        ret_code_t err_code;
    
        //The array must be static because a pointer to it will be saved in the button handler module.
        static app_button_cfg_t buttons[] =
        {
            {LEDBUTTON_BUTTON, false, BUTTON_PULL, button_event_handler},
            {SLEEPBUTTON_BUTTON, false, BUTTON_PULL, button_event_handler}
        };
    
        err_code = app_button_init(buttons, ARRAY_SIZE(buttons),
                                   BUTTON_DETECTION_DELAY);
        APP_ERROR_CHECK(err_code);
    }

    int main(void)
    {
        // Initialize.
        ....
    
        // Enter main loop.
        for (;;)
        {
            if (m_is_sleep_mode)
            {
                nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF);
            }
            else
            {
                idle_state_handle();        
            }
        }
    }
    
    

  • Have you taken a look at the nrf_pwr_mgmt example? That might give you a better understanding of the System OFF sleep mode.

  • Try changing NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF  with NRF_PWR_MGMT_SHUTDOWN_STAY_IN_SYSOFF.

Related