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

Need to switch BLE off and on

I am developing based on ble_app_uart example of SDK12 for nRF51 DK and I need to switch BLE off completely when power disappears to save battery and switch back on when power is restored. How can I proceed?

In detail, I need answers to the following situations:

1) Power fails during active connection: how to detect that it is connected and how to disconnect the connection?

2) How can I then switch off BLE completely (stop advertising and switch radio off)?

3) What sequence should be called to restart advertising when power is back?

  • Hi Sergio, 

    Is the NRF51 powered by both battery and a power supply? If so how are you switching between battery and power supply?

    The nRF51 has a Power Failure Comparator that can configured to generate an event when the supply voltage drops below a certain threshold, see the POFCON register in the nRF51 Reference Manual. You could also use the Low Power Comparator for this. 

    Q1: You can check the connection handle, m_conn_handle. It is non-zero if you have a connection and is set to BLE_CONN_HANDLE_INVALID = 0xFFFF if no connection is active. To disconnect you call sd_ble_gap_disconnect() with the connection handle and a hci_status_code. 

    Q2: Call sd_ble_gap_adv_stop() to stop advertising. The Radio will then be automatically switched off. 

    Q3: Call ble_advertising_start(BLE_ADV_MODE_FAST) to start advertising again. 

    Best regards
    Bjørn

  • Thanks Bjorn.

    I'll try the BLE power on and off tomorrow and let you know here the result.

    Usually I use a HW detector (my board will be supplied with AC voltage) so I detect mains failure within 20 ms. The advantage is I can stop the peripherals and controller while voltage is still OK, guaranteeing that the controller always starts when power gets back.I know that controllers have Brown Out Reset detectors but even those sometimes hang the controller when voltage oscillates around the detection point.

    Anyway, I'll give it a try at a later stage.

    Thanks for the tips.

  • Understood. Let me know if you run in to any issues with the API mentioned below. 

Related