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.

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

Reply Children
  • I'm not aware of any ways to detect that the device is restarted due to a brownout reset. All peripherals are reset similar to a power on reset. The device should still be able to enter low power mode by calling the correct sleep functions.

  • I got it to error in a way I am hoping can explain why it goes into this non shutdown state. 

    System goes like this:

    2 boards: button board and motor board

    push button on button board and it scans, connects, sends turn motor command

    motor board after receiving turn motor command, turns motor and sends done command back to button board

    button board having received done command, disconnects.

    If the motor board remains connected for longer than 10 seconds, it will disconnect on its own.

    I have a debug LED that turns on when the motor board enters BLE_GAP_EVT_CONNECTED and it turns off when it calls BLE_GAP_EVT_DISCONNECTED. 

    The system appears to work if i do not turn the command. If i receive the command and respond ignoring the motor turn command 

    In the following section I get a NRF_ERROR_CONN_COUNT

    void advertising_start(bool erase_bonds)
    {
        ret_code_t err_code = NRF_ERROR_INVALID_STATE;
    
        if (erase_bonds == true){
            delete_bonds();
            // Advertising is started by PM_EVT_PEERS_DELETED_SUCEEDED event
        }else{
            if(!is_advertising){
              err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);      /**< Follows ble_app_blinky example */
              APP_ERROR_CHECK(err_code);
    
              is_advertising = true;
            }
        }
    }

    I have my peripheral count set to 7 and central count set to 1 in the sdk_config file. 

    Am I making multiple connections or something that is eating into my connected count or is there a disconnect all function that will reset everything. Because once it goes into this state, even after brownout and reset, it does not go into low power mode again. I HAVE to disconnect power and restart it and it will start in low power mode (0.6mA) for a couple cycles but will always ned using 8mA eventually and only way to stop it is to remove power.

  • Did you configure the link conts using defines NRF_SDH_BLE_PERIPHERAL_LINK_COUNT and NRF_SDH_BLE_CENTRAL_LINK_COUNT in the sdk_config.h file? Did you also increase NRF_SDH_BLE_TOTAL_LINK_COUNT to the sum of the two last parameters? It is the last parameter that is used to configure the allowed link count for the softdevice. You get an event whenever a connection is established and disconnected, so you should be able to keep track of how many connections are active at any time.

  • yes i think iwas able to correct this issue. I think this was an issue with being new to nRF and the examples. I was establishing 2 NRF_OBSERVERS to do the same thing. 1 in my _DEF() and 1 in the advertising_init(). After i removed the observer in the advertising_init() things cleared up.

    if i put the system in sd_power_off(), and never trigger the wake_on pin, is there anything else that can wake the system up to scan or anything? or the only way wake it up from sd_power_off() is a physical interaction of sorts. Meaning it just sitting there isnt going to wake up on its own randomly and then go back to power_off?

  • The only possible wakeup sources from System OFF is described in the documentation.

Related