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.

  • Hey,

    First, I would advise you to try the ble_uart example in the peripheral folder. With that you can set up a simple uart link between your nrf52 board and android device and send messages either way.

    To put the board into low power, with the softdevice enabled, you should use the sd_app_evt_wait function. You can put this in your main loop so that the device goes to sleep when it has nothing else to do. This will be SYSTEM ON mode. So you can send a message from the android device and it will wake up the nrf.

    You can also use SYSTEM OFF mode, as you said. When you put the device in SYSTEM OFF mode, the BLE link will be closed, the device will be disconnected. You can wake up the device using a GPIO interrupt ,NFC or LPCOMP interrupt. This will provide you with lowest power consumption but the nrf when wakes up, will be like it has been reset.

    Also, do check the documentation if you have any further question.

  • Have you taken a look at the examples in SDK 15.2? In most of the examples, the chip is in System ON sleep mode most of the time. The way it is done is by putting the sleep function in a for loop (as Ashish mentioned). Most of the functionality related to the nRF52 chip is event driven, and is perfectly compatible with this approach.

    E.g, in the SAADC example, the chip is put to System ON sleep in a while(1) loop through the function nrf_pwr_mgmt_run(), then if  ADC data is received, the chip breaks the sleeps mode, handles the ADC event, then continues on the line after nrf_pwr_mgmt_run(). Since the function is inside a while loop, it will loop around and go to sleep once again.  The BLE examples are also event driven, and works in the same manner as the ADC example. 

    This approach only works for System ON sleep mode, and event driven activity.

    However, please tell me if you are aware of this and have a reason for invoking sleep mode yourself. If you could explain your project in more details, I would be able to give you a more constructive answer.

    Best regards,

    Simon

  • Thank you for the reply Simon.

    So I am aware of the SDK samples, probably didn't fully understand what they were doing, so thank you (and Ashish) for clarifying.

    For the project that I am working on, I would like to send a sleep command to the BLE board from an Android device (untethered so not through uart), similar to the Blinky app where you press a switch control to turn a light on the board. I was unsure the correct steps to follow to simulate this event and how one would get the board to go to sleep.

    1. So for now what I would like to do is to create an LED type event structure for an Android app (e.g. sleep button) that could put the board into sleep mode (System OFF), essentially turn it off where a person would have to press the reset button on the board to wake it up (how do you put the board into System OFF sleep?).

    2. Then as a later goal to implement the System ON mode where an event from the Android app could put the board to sleep and then another event (say turning a switch control on/off) to wake it up.

    Any ideas?

  • Question 1

    There are many ways of doing this, but here I am presenting one approach. You could use the ble_app_uart peripheral example along with nRF Connect for Mobile as a starting point. Then you could put the board into System OFF sleep mode, if a specific message (e.g. 123) is received. In order to achieve this you have to modify the function nus_data_handler(), specifically you need to check if the received data is equal to the correct value (e.g. 123), and run sd_power_system_off() if that is the case.

    If you are developing your own mobile app, you could make a button that only sends out the specific message. 

    Question 2

    For putting the board into System ON, you could use the same approach as explained above, just with another value (e.g. 456). I would recommend you to take a look at the Button handling library, which will generate GPIOTE events when a button is pressed, and consecutively wake the device up from System ON sleep.

    Best regards,

    Simon

  • Thanks again for the reply and ideas on how to solve my questions.

    So just to make sure, if I use the SDK blinky app example, I believe it already implements System ON mode, as I can see that  nrf_pwr_mgmt_run() is run in a for(;;) loop. So what I tried was to add another button event handler in the SDK to say Button 2 of the dev board, that calls sd_power_system_off() to test if i can put the board in system OFF mode but that doesn't seem to work.

    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? 

Related