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

ble_app_hids_mouse does not resume advertisement

Hello Guys,

I'm implementing the ble_app_hids_mouse. I can pair with Windows, I see the mouse arrow moving around etc everything looks good except when I tell Windows to disconnect.

Upon disconnection I'm expecting the nRF51822 to resume advertisement below is my code:

    case BLE_GAP_EVT_DISCONNECTED:
        
        m_conn_handle = BLE_CONN_HANDLE_INVALID;

        m_advertising_mode = BLE_DIRECTED_ADV;
        m_direct_adv_cnt   = APP_DIRECTED_ADV_TIMEOUT;
        radio_connected = BLE_GAP_EVT_DISCONNECTED;
        mouse_timer_stop();
        advertising_start();
        break;

I put a break point in there and I saw that the event is being triggered but no advertisement. Sometimes, I see that err_code = sd_ble_gap_adv_start(&adv_params) is failing with error_code == 7.

Any ideas about what's is happening? It is the only thing that is holding me up. I don't have visibility inside of sd_ble_gap_adv_start() to know what's wrong.

Thanks, Gilson

  • Hello Gilson,

    That error is a NRF_ERROR_INVALID_PARAM so there is something about your advertising parameters that the stack does not like. So, I think you are probably going to need to consult the documentation on the allowed settings to see which one(s) the stack is not happy with.

    Regards, John

  • I agree with John here, any chance you could verify the content of the input parameters for the sd_ble_gap_adv_start? ble_gap_adv_params_t is defined in ble_gap.h. Any of the values you have that are outside the what's stated there?

    Might be a silly add on as you should get a different error message if this was true, but it's worth making sure that you have gotten the disconnect event before you start advertising.

  • When I posted the question I was hoping that someone had a technique to debug sd_ble_gap_adv_start() returning error code = 7 is very broad there are many parameters that could be bad.

    So my solution to this problem: I saved the value of the parameters in a global variable and during the crash I compared the parameters against the values of a good advertisement and I saw some fields were not set.

    But the real reason the fields did not get set was because inside of the code "case: BLE_SLOW_ADV" m_advertising_mode is getting set to BLE_SLEEP next time that function is called with m_advertising_mode = BLE_SLEEP it will NOT set some fields properly and cause the crash.

    My fix to the problem, I just commented out

    // m_advertising_mode  = BLE_SLEEP;
    

    Allowing m_advertising_mode = BLE_SLOW_ADV caused my HW NOT to crash anymore and I see advertisements and my Windows 8.1 can reconnect everytime.

Related