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

  • 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?

Reply Children
  • 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;

  • If you pass an error to APP_ERROR_CHECK, the application will jump to the error handler function. If you have set the DEBUG flag, you will be stuck in a loop here until manually resetting the chip. This would explain your high current consumption.

  • Are APP_ERROR_CHECK() simply for debugging and prototyping? I feel like i am getting in race conditions.

    I have 2 boards. button board and motor board.

    void tb_ble_power_off(void)
    {
        uint32_t err_code;
        
        if(m_conn_handle != BLE_CONN_HANDLE_INVALID){
            err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
        }
    
    If they both try and power_off at the same time can they both pass through that if statement but only 1 succeed?

    I want to have the button board to do the disconnecting, but if something wonky happens and the motor boards remains connected for longer than 10 seconds, i want it to disconnect from whatever it is connected to.

    Also what would cause an NRF_ERROR_IVALID_STATE top be thrown on the scanner here:

     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;

  • APP_ERROR_CHECK() can be used for final product as well, to reset the device if unexpected errors happen, but you should verify that your product does not generate errors during development phase.

    I'm not sure I understand, is there a connection between the button board and the motor board? I don't see the point in calling the disconnect function on both sides, calling it on one side should be enough. Like you say, you could get in a situation where the softdevice receive disconnect from other side of link right after checking m_conn_handle != BLE_CONN_HANDLE_INVALID, resulting in an error code being reported since no connection is available.

  • Is there a way to check if the system did a brown out reset? When i turn the motor on it drops the input voltage a lot and sometimes causes the chip to reset. When it comes back from brown out reset though, it does not return to low power mode like if I turn power off and back on.

Related