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

Not able to wake the board from deep sleep(System off)

I am very new to Nordic products so please excuse my ignorance.I have been trying to put my nrf52840 board to deep sleep. It seems to go to sleep but when I try to wake it up by pushing the buttons, it doesn't wake up.

This is how  I modified Ble_app_blinky_c, I added sleep_mode_enter(){}, buttons_leds_init(){}, and bsp_event_handler(bsp_event_t event){} from Ble app template . And then I am calling buttons_leds_init  and sleep_mode_enter in Main.c.Basically I want the board to be in deep sleep at all times and wake up only when I push the buttons.

I have included my project below.

What I am doing wrong?

Thank you in advanceble_app_blinky_c.zip

  • I can see SUPERVISION_TIMEOUT could have been useful but in my case I want it to go to sleep right after the data has been sent. So basically when you push the button,it wakes up, connects to peer board, sends data to it(data sent will depend on the button pushed, that is why I was trying to put this on button event handler ), and then it goes back to sleep.In other words, the board will be forced out of connection as a result of the central going to sleep.

  • Okay, thank you for clarifying! Then I guess you want to disconnect (using sd_ble_gap_disconnect) after the data has been transferred, so call the disconnect when the data has been received by the peripheral and then go to sleep after you've disconnected.

    As for the data being sent depending on what button you push, I don't think you can set this with the same button push you wake up the device with. So I think you either have to press the button twice, once for wake-up and once for what data you are to send or holding the button and set an "if BTN1 is held, send data 1" after the device has woken up.

    Best regards,

    Simon

  • Thank you Simon.

    I have been trying to play with code a bit, now my challenge is getting connection_handle instance in button_event_handler.I am trying to the board to sleep after the data has been successfully sent, but we don't have access to the conn_handle in order to disconnect in button_event_handler. See code below

    case LEDBUTTON_BUTTON_PIN:
                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);
                    //sd_ble_gap_disconnect(conn_handle,BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); 
                    sleep_mode_enter();
                }
                break;

  • Hi David

    Do you start scanning and connect to a peripheral at any point before this though? You can't disconnect if you're not connected already. You'll also get the conn_handle upon connecting to another device, as the conn_handle is in the initial message. You'll have to save and use this in calls that require it. I believe just about any of our examples using BLE saves the conn_handle upon connection though.

    On a somewhat unrelated note, I think you should put the disconnection and sleep events outside of the button_event_handler, and rather do these operations after the button_event_handler.

    Best regards,

    Simon

  • Hi Simon

    I was scanning and connecting to a peripheral before disconnecting, I was not saving the connection_handle in beginning.

    This time I tried to disconnect after data is sent in button_event_handler and put to sleep in BLE_GAP_EVT_DISCONNECTED case in ble_evt_handler , that didn't work either,it disconnect but , it doesn't go to sleep at all.

    Where outside of button_event_handler were you thinking?

Related