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 Reply Children
  • Yes, I would suggest starting with this Template Application example which might be closed to your requirement.

    -Amanda H.

  • I tried to put my App in deep sleep but it doesn't work the way  I want it to. This is what I did, I added a sleep_mode_enter() function to main.c and tried to call it in button_event_handler, after the button is pressed. The outcome was, the board seems to go sleep but when I press the button again, it doesn't wake up.

    Basically all I want to do is the board to be in deep sleep at all times.It will only wake up only when the button is pushed. When a button is pushed, then it will connect to the nearby server-peripheral kit and turn the LED on that board/server.

    The reason I don't want to start from  Template Application is that I already have an Application with several features, so it would just be easier to add deep sleep capability to the existing application instead of starting from scratch again. 

    I have attached my project below, I would greatly appreciate your help.I am using SDK 15.3.

    
    static void button_event_handler(uint8_t pin_no, uint8_t button_action)
    {
        ret_code_t err_code;
    
        switch (pin_no)
        {
            case LEDBUTTON_BUTTON_PIN:
                NRF_LOG_INFO("Button 1 is pressed");
                err_code = ble_lbs_led_status_send(&m_ble_lbs_c, button_action);
                if (err_code != NRF_SUCCESS &&
                    err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
                    err_code != NRF_ERROR_INVALID_STATE)
                {
                    APP_ERROR_CHECK(err_code);
                }
                if (err_code == NRF_SUCCESS)
                {
                    NRF_LOG_INFO("LBS write LED state %d", button_action);
                    sleep_mode_enter();
                }
                break;
                }
    ..........
    
    
    static void sleep_mode_enter(void)
    {
        ret_code_t err_code;
    
        err_code = bsp_indication_set(BSP_INDICATE_IDLE);
        APP_ERROR_CHECK(err_code);
    
        // Prepare wakeup buttons.
        err_code = bsp_btn_ble_sleep_mode_prepare();
        APP_ERROR_CHECK(err_code);
    
        // Go to system-off mode (this function will not return; wakeup will cause a reset).
        err_code = sd_power_system_off();
        APP_ERROR_CHECK(err_code);
    }

    ble_app_blinky_c.zip

  • Hi, 

    I suggest you study how to initial bsp and use bsp event to call the sleep_mode_enter() in Template Application example. 

     bsp_init() -> app_button_enable() -> app_button_enable() -> nrfx_gpiote_in_event_enable(): Function for enabling sensing of a GPIOTE input pin.

    -Amanda H.

Related