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

How to put nrf52840 to deep sleep(SYSTEM OFF)

Hi all

I am using nrf52840 kit, and I have a  simple BLE app(client/central that turn LED on to a connected server/peripheral) running on it(sdk 15.3). Now I want to put it on deep sleep(SYSTEM OFF) by default. When a button is pushed, then it will connect to the nearby server-peripheral kit and turn the LED on that server.So it is simply that the client will come out of deep sleep only when a button is pushed.

I have looked around for an example to get started with no luck.But so far I have learned that I can use sd_power_system_off() to put it to sleep. Based on my findings I have the following questions

  1. It seems like I have to prepare to wake up buttons and turn peripherals off, but how do I do this?
  2. Where do I place the function for deep sleep in Main.c (see code snippet below)?
  3. Any example that would help me get started, I would greatly appreciate it.

I found this post but still is not that informative

int main(void)
{
    // Initialize.
    log_init();
    timer_init();
    leds_init();
    buttons_init();
    power_management_init();
    ble_stack_init();
    gatt_init();
    db_discovery_init();
    led_service_client_init();

    // Start execution.
    NRF_LOG_INFO("BLE Lightbulb Remote Control started.");
    scan_start();

    // Turn on the LED to signal scanning.
    bsp_board_led_on(CENTRAL_SCANNING_LED);

    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}

Parents
  • Hi, 

    The nRF52840 can be put into System OFF mode by calling sd_power_system_off(), which puts the system to the deepest power-saving mode.

    The system can be woken up through a DETECT signal generated by GPIO pins. Configurations of individual pins are done through the SENSE field in the PIN_CNF[n] register and can be set by calling nrf_gpio_cfg_sense_input(...). However, system OFF will disable all peripherals except for GPIO, LPCOMP, and NFC, and after waking up the system gets reset.

    Another possibility is to put the system into System ON sleep mode, where the system will wake up on any event, and can be invoked by calling sd_app_evt_wait(). All the peripherals can be used and you can use GPIOTE interrupts to wake it up.

    You can refer to the Power Profiling Application example. This sample application starts up, configures wakeup buttons, and enters the System OFF mode. On button presses, the application wakes up and goes into either 'Connectable mode' or 'Non-connectable mode' based on which button is pressed.

    For more information on both modes, see sd_app_evt_wait and the nRF5 Series User Specification (Section: POWER - Power control).

    -Amanda H. 

Reply
  • Hi, 

    The nRF52840 can be put into System OFF mode by calling sd_power_system_off(), which puts the system to the deepest power-saving mode.

    The system can be woken up through a DETECT signal generated by GPIO pins. Configurations of individual pins are done through the SENSE field in the PIN_CNF[n] register and can be set by calling nrf_gpio_cfg_sense_input(...). However, system OFF will disable all peripherals except for GPIO, LPCOMP, and NFC, and after waking up the system gets reset.

    Another possibility is to put the system into System ON sleep mode, where the system will wake up on any event, and can be invoked by calling sd_app_evt_wait(). All the peripherals can be used and you can use GPIOTE interrupts to wake it up.

    You can refer to the Power Profiling Application example. This sample application starts up, configures wakeup buttons, and enters the System OFF mode. On button presses, the application wakes up and goes into either 'Connectable mode' or 'Non-connectable mode' based on which button is pressed.

    For more information on both modes, see sd_app_evt_wait and the nRF5 Series User Specification (Section: POWER - Power control).

    -Amanda H. 

Children
  • Thank you, Amanda, for the response.

    1. You mentioned that in Power Profiling Application example shows how to configure wakeup buttons, but I didn't see, where they are doing that , also I tried to look for  nrf_gpio_cfg_sense_input method in the example I didn't find it in the example.
    2. In the post I referenced above Simonr used  bsp_btn_ble_sleep_mode_prepare() to prepare wake up buttons, what is the difference between  bsp_btn_ble_sleep_mode_prepare() and nrf_gpio_cfg_sense_input ,which one should I use?
    3. I know I can use  sd_power_system_off() but my question still remains where can I put that, Can I place it anywhere I want in the Main.c 's int main(void){} without causing any issues?
  • Hi, 

    davidm said:
    You mentioned that in Power Profiling Application example shows how to configure wakeup buttons, but I didn't see, where they are doing that , also I tried to look for  nrf_gpio_cfg_sense_input method in the example I didn't find it in the example.

    It's the DETECT signal that wakes the chip up from the system off sleep. So the gpio needs to enable sense mechanism. This is done in as part of buttons_init() -> bsp_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS, NULL);

    davidm said:
    In the post I referenced above Simonr used  bsp_btn_ble_sleep_mode_prepare() to prepare wake up buttons, what is the difference between  bsp_btn_ble_sleep_mode_prepare() and nrf_gpio_cfg_sense_input ,which one should I use?

    In the SDK12.3 ble_app_uart_c, we use sleep_mode_enter(); -> bsp_btn_ble_sleep_mode_prepare(); -> bsp_wakeup_button_enable() -> wakeup_button_cfg(button_idx, true); -> nrf_gpio_cfg_sense_set() to prepare wake up buttons. Please also see nRF5 SDK v15.3.0: GPIO HAL. In SDK 15.3 ble_app_uart_c, it's done in shutdown_handler. 

     

    davidm said:
    I know I can use  sd_power_system_off() but my question still remains where can I put that, Can I place it anywhere I want in the Main.c 's int main(void){} without causing any issues?

     It supposes not causing any issues. In the examples, it calls nrf_pwr_mgmt_shutdown() -> shutdown_process(); -> sd_power_system_off();

    -Amanda H. 

  • Thank you Amanda,thank you again for the explanation. According to the details you provided above,my understanding is, In order to add deep sleep capability, I need to do to 3 things (and please correct my understanding if is wrong).

    1. First I need to enable GPIO sense mechanism. And this can be done in bsp_init, but the question is where do I pass the value to enable?   
    2. The second thing is I need to configure wake up buttons, and I should be able to do this by registering shutdown_handler as it's done in 15.3 ble_app_uart_c. Question is how is NRF_PWR_MGMT_HANDLER_REGISTER used?
    3. Third thing is to call nrf_pwr_mgmt_shutdown anywhere inside main(void). But the question is, which files I need to include in order to use nrf_pwr_mgmt_shutdown?
  • Hi,

    davidm said:
    First I need to enable GPIO sense mechanism. And this can be done in bsp_init, but the question is where do I pass the value to enable?   

     buttons_init() -> bsp_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS, NULL); -> app_button_init -> GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);

    The sense mechanism will be set for that pin.

     

    davidm said:
    how is NRF_PWR_MGMT_HANDLER_REGISTER used?

    Please this page NRF_PWR_MGMT_HANDLER_REGISTER

     

    davidm said:
    which files I need to include in order to use nrf_pwr_mgmt_shutdown?

     nRF5_SDK_15.3.0_59ac345\components\libraries\pwr_mgmt\nrf_pwr_mgmt.c

    I suggest starting with this Template Application example. 

    The Template Application is an application that you can use as a starting point for developing your own application, using the hardware delivered in the nRF5 Development Kit. The application will stop advertising after 3 minutes and then go to system-off mode. To wake it up, press Button 1, and it will start advertising again.

    -Amanda H. 

  • Thank you Amanda.

    So it seems like all I need to do is include button_init to enable pin sense mechanism, add shutdown_handler function and register it....and call nrf_pwr_mgmt_shutdown to put it to sleep, is that correct?

    Regarding prepare buttons for wake up, in SDK 15.3 ble_app_uart_c, shut_down_handler is being used , but in other examples(Power Profiling Application and Template Application ) is not there, what are they using instead?

Related