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

Advertising and sleep

I tried searching for this response but cant find exact answer

SDK15.2 and API6.1

I am trying to have an advertiser but would like to put it in some sleep mode and advertise. if i do sd_power_system_off() it turns off until i hit the wake GPIO. I tried using sd_app_evt_wait(), however that too doe snot seem to allow me to advertise and sleep at the same time.

What is recommended call to put the thing to sleep but be able to wake on ble event when the scanner tries to connect.

Parents
  • Hi,

    It is not possible to advertise when you are in deep sleep. In system off mode, all clock sources will be turned off, and you will only be able to wake on certain peripherals (reset, GPIO, NFCT, LPCOMP).

    It is also not possible to "advertise and sleep at the same time". You can enter system on idle mode between advertising events, but the chip will wake up to process and prepare advertising, as the CPU is required to start the advertising and setup buffers, etc.

    Running sd_app_evt_wait() in the main-loop is the correct way to enter lowest possible sleep mode while doing advertising and receive connection events.

    Best regards,
    Jørgen

Reply
  • Hi,

    It is not possible to advertise when you are in deep sleep. In system off mode, all clock sources will be turned off, and you will only be able to wake on certain peripherals (reset, GPIO, NFCT, LPCOMP).

    It is also not possible to "advertise and sleep at the same time". You can enter system on idle mode between advertising events, but the chip will wake up to process and prepare advertising, as the CPU is required to start the advertising and setup buffers, etc.

    Running sd_app_evt_wait() in the main-loop is the correct way to enter lowest possible sleep mode while doing advertising and receive connection events.

    Best regards,
    Jørgen

Children
  • Do i have to call sd_app_evt_wait() after each time i send advertising? or if during the BLE_GAP_EVT_DISCONNECTED call i do the following, would it go into semi sleep advertising cycles? or do i need to put it in the idle_state_handle()?

    case BLE_GAP_EVT_DISCONNECTED:
                m_conn_handle = BLE_CONN_HANDLE_INVALID;
                
                err_code = sd_app_evt_wait();
                APP_ERROR_CHECK(err_code);
    
                advertising_start(false);
                break;

  • Put it in idle_state_handler. As long as you do not have any blocking loops in your application, the application will enter the idle_state_handler when there is no more work to be done, allowing the CPU to go to sleep. This is what we do in all our BLE examples in the SDK.

  • Is there something i am missing here. that may be mis representing actual results

    I am running the code in debug mode and i am pulling 8mA of current. I am re-writing some code and right now all it is doing is is sitting there advertising, yet i am pulling 8mA whereas before i was pulling 0.8mA. How do i adjust the advertising duration ands interval with respect to the scanner so as I can achieve an advertisement. 

    I tried adjusting the APP_ADV_DURATION and APP_ADV_INTERVAL but if i adjust those from the values to shorter ones to reduce current draw, i cannot see them advertising in the nRF connect app. 

    How can i choose proper ADV and SCAN DURATION, INTERVALS and WINDOWS so that i can get best power consumption

  • Sounds like you are not going to sleep, the CPU will consume ~7-8 mA when running if you have not enabled the DCDC converter. Try resetting the board before measuring current to make sure the chip is not in debug mode, this will give you increased current consumption, as the CPU is needed by debugger to read registers. Which example are you running, and what changes have you done?

  • I am using the ble_app_blinky and ble_app_blinky_c examples as a base. I am not using an eval board but rather my PCB so have a custom bsp file. I have a button on 1 PCB and a motor on the other. I want to turn motor when i push the button. So the LED transfer data i changed to a uint8_t command. and that is pretty much it. Added some lines of code in the CONNECTED and DISCONNECTED ble_evt_handler to turn motor. but nothing that should keep it on. 

    i work off all handlers so my main for loop is still the same as the example. and the only thing I added to the idle_state_handler was the sd_app_evt_wait(). 

    I did reset the chip and it appears to drop to 0.6mA but after i do a couple connects and disconnects and turn the motor once or twice the current jumps back up to 8mA.

    also, it appears when the current does not drop i loose function in my button board until i do a hard reset on it. SO i think it does not fully disconnect. Even though DISCONNECTED gets called because LED turns off showing it reached DISCONNECTED in ble_evt_handler.

    Debugging more on the button PCB i keep getting NRF_ERROR_INVALID_STATE in the following APP_ERROR_CHECK(). 

    I do the following. button board on button press wakesup from sd_power_off() and scans. after connecting, it sends command to motor PCB. motor PCB turns motor and and after completes sends a completed action command back to button board. button board should than disconnect. however when sending a repsonse back i get the param update error.

    case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
                // Accept parameters requested by peer.
                if (m_conn_handle != BLE_CONN_HANDLE_INVALID){
                    err_code = sd_ble_gap_conn_param_update(p_gap_evt->conn_handle,
                                                &p_gap_evt->params.conn_param_update_request.conn_params);
                    APP_ERROR_CHECK(err_code);
                }
                break;

Related