This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

what's the meaning of error no. NRF_ERROR_BUSY

When I use sd_ble_gap_adv_start( ), sometimes get return value NRF_ERROR_BUSY . What's the meaning of this error No. ?

  • In what case are you getting NRF_ERROR_BUSY? Completely at random or when button is pressed around 1s advertising timeout? My only assumption is that when you pressing on button in that moment previous advertising is timed out and stopped (or stopping) and softdevice generate BLE_GAP_EVT_TIMEOUT event (BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT), but it's pending and this pending event block your sd_ble_gap_adv_start() call. If you are using scheduler, then try to do this:

    if (sd_ble_gap_adv_start() == NRF_ERROR_BUSY)
    {
        app_sched_execute();
        sd_ble_gap_adv_start();
    }
    
  • I tried, but can't solve the problem...

  • So in what situation do you get NRF_ERROR_BUSY? Only when you press on button while advertising? Or around 1s advertising timeout? Or after 1s advertising timeout? Or at random?

  • it is after 1s; if i press the button quickly, no error get.

  • I don't know, what are you doing wrong, but this works for me without any error:

    static bool advertising_state = false;
    
    static void on_ble_evt(ble_evt_t * p_ble_evt)
    {
        uint32_t        err_code;
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GAP_EVT_CONNECTED:
                advertising_state = false;
    ...
            case BLE_GAP_EVT_TIMEOUT:
                if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT)
                {
                    led_off(ADVERTISING_LED_PIN_NO);
                    advertising_state = false;
                }
                break;
    ...
    }
    
    static void advertising_start(void)
    {
    
        uint32_t             err_code;
        ble_gap_adv_params_t adv_params;
        ble_gap_whitelist_t  whitelist;
        uint32_t             count;
        
        advertising_state = true;
        led_off(ADVERTISING_LED_PIN_NO);
    ...
        adv_params.timeout  = 1;
    ...
        err_code = sd_ble_gap_adv_start(&adv_params);
        APP_ERROR_CHECK(err_code);
        
        led_on(ADVERTISING_LED_PIN_NO);
    }
    
    static void button_event_handler(uint8_t pin_no, uint8_t button_action)
    {
        if (button_action == APP_BUTTON_PUSH)
        {
            switch (pin_no)
            {
                case KEY_PRESS_BUTTON_PIN_NO:
                {
                    uint32_t err_code;
                    if (advertising_state == true)
                    {
                        err_code = sd_ble_gap_adv_stop();
                        APP_ERROR_CHECK(err_code);
                    }
                    advertising_start();
                    break;
                }
                default:
                    APP_ERROR_HANDLER(pin_no);
                    break;
            }
        }
    }
    
Related