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

how to turn off and on BLE service dynamically

My application uses a NRF52 (SD132, SDK 15.0.0), very simple circuit and needs to be extremely low current consumption. I measured the current in conditions of BLE on and BLE off. To turn on BLE, I use the following code:

ble_stack_init();
gap_params_init();
gatt_init();
services_init();
advertising_init();
conn_params_init();
advertising_start(erase_bonds);

The current is about 0.6mA. Without the code above, my application is still working (no bluetooth connection of course), and the current drops to 6uA.

My intention is: to turn on BLE when hard button is pressed and turn it off when transmission is finished. My question is: how do I turn off and then turn on BLE dynamically, without reset the whole environment. I guess turning on seems easy, using the code above. But turning off and remaining CPU running? How do I do that?

Thanks a lot. Dimtai 10/29/2018

Parents
  • Hi,

    If I understand you correctly, then you are saying that if you comment out: 
    // advertising_start(erase_bonds);

    Then the current consumption is about 4uA, that should be the case. Otherwise I suspect you have some peripherals enabled or logging enabled in some way.

    The current consumption when you advertise depends on the advertisement interval and you can try to get some current consumption estimations here:
    https://devzone.nordicsemi.com/power/ 

    It is of course possible to disable the softdevice, but it should not be necessary. Instead you simply stop advertising or disconnect the link when you have transferred whatever you wanted to transfer.

    Best regards,
    Kenneth

  • Many thanks Ken.

    Yes the current would drop to only a few uA if ble_advertising_start() is off. Your suggestion of disconnection sounds like a good solution. But I searched API and could not find ble_advertising_stop() command or something like that.  Any hints?

    Another related issue is writing to flash. I can write to chip flash successfully before ble services start (ble_stack_init() in my code). However, I can never write the flash after ble services are on. I heard people saying that ble needs to be stopped in order to write flash. I guess the same principle applies here. am I right?

    Best regards, Dimtai 10/30/2018

  • You should be able to call ble_advertising_start(BLE_ADV_MODE_IDLE); and sd_ble_gap_adv_stop(); to stop advertising.

    It is possible to write to flash after enable softdevice, but then you typically need to use the FDS or fstorage. This module is typically already included by the peer manager if you are supporting bonding, so then you need to refer to documentation and/or find examples here in devzone on usage of FDS or fstorage.

    Best regards,
    Kenneth

Reply
  • You should be able to call ble_advertising_start(BLE_ADV_MODE_IDLE); and sd_ble_gap_adv_stop(); to stop advertising.

    It is possible to write to flash after enable softdevice, but then you typically need to use the FDS or fstorage. This module is typically already included by the peer manager if you are supporting bonding, so then you need to refer to documentation and/or find examples here in devzone on usage of FDS or fstorage.

    Best regards,
    Kenneth

Children
Related