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

ble_db_discovery_start doesn't complete with specific phone

My project uses nRF52840-DK to connect, bond and discover a custom service with two characteristics (TX and RX) and RX Characteristic has a CCCD (0x2902).

The flow of the software goes as follow:

1) the nRF connects to the phone

2) the nRF bonds to the phone

3) the nRF starts discovery of the service

4) the nRF reads/writes from/to the phone using the service

This works as expected with different phones I tried (Galaxy S6, S6 Edge and S7, android versions 7.0, 7.0 and 8.0). but when using Galaxy A31 android version 10.0 I can't complete discovery. I added a print to ble_db_discovery_on_ble_evt() and noticed that with the issued phone I don't get the events with BLE_GATTC_EVT_CHAR_DISC_RSP (50) and BLE_GATTC_EVT_DESC_DISC_RSP (51) which I do get with the working phones.

Furthermore, the issued phone gets a disconnect after some time with error BLE_HCI_CONNECTION_TIMEOUT, which I believe happens because the discovery prevents the nRF to maintain the connection (I saw that with out calling  ble_db_discovery_start the connection doesn't disconnect after a long time).

Does anyone have an idea why this happens?

Thanks in advance

Log of working phone:

<debug> ble_db_disc: Starting discovery of service with UUID 0x1101 on connection handle 0x0.
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Primary Services Discovery Request
<debug> nrf_ble_gq: Processing the request queue...
<debug> ble_db_disc: XXXX: ble_db_discovery_on_ble_evt 48
<debug> ble_db_disc: Found service UUID 0x1101.
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Characteristic Discovery Request
<debug> nrf_ble_gq: SD GATT procedure (3) succeeded on connection handle: 0.
<debug> nrf_ble_gq: Processing the request queue...
<debug> ble_db_disc: XXXX: ble_db_discovery_on_ble_evt 50
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Characteristic Discovery Request
<debug> nrf_ble_gq: SD GATT procedure (3) succeeded on connection handle: 0.
<debug> nrf_ble_gq: Processing the request queue...
<debug> ble_db_disc: XXXX: ble_db_discovery_on_ble_evt 50
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Characteristic Descriptor Request
<debug> nrf_ble_gq: SD GATT procedure (4) succeeded on connection handle: 0.
<debug> nrf_ble_gq: Processing the request queue...
<debug> ble_db_disc: XXXX: ble_db_discovery_on_ble_evt 51
<info> ble_db_disc: 0 cccd_handle 43
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Characteristic Descriptor Request
<debug> nrf_ble_gq: SD GATT procedure (4) succeeded on connection handle: 0.
<debug> nrf_ble_gq: Processing the request queue...
<debug> ble_db_disc: XXXX: ble_db_discovery_on_ble_evt 51
<debug> ble_db_disc: Discovery of service with UUID 0x1101 completed with success on connection handle 0x0.
<info> app: Discovery complete.

Log of issued phone:

<debug> ble_db_disc: Starting discovery of service with UUID 0x1101 on connection handle 0x0.
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Primary Services Discovery Request
<debug> nrf_ble_gq: Processing the request queue...
<debug> ble_db_disc: XXXX: ble_db_discovery_on_ble_evt 48
<debug> ble_db_disc: Found service UUID 0x1101.
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Characteristic Discovery Request
<debug> nrf_ble_gq: SD GATT procedure (3) succeeded on connection handle: 0.
****AFTER A FEW SECONDS*****
<debug> ble_db_disc: XXXX: ble_db_discovery_on_ble_evt 17
<info> app: Disconnected. conn_handle: 0x0, reason: 0x8

Parents
  • The disconnect reason is BLE_HCI_CONNECTION_TIMEOUT (0x08), so I suspect that the lfclk tolerance is marginally out of spec.

    Can you provide the parameters you have set for the clock_lf_cfg that is passed to sd_softdevice_enable()?

    Kenneth

  • Thanks for the reply Kenneth,

    I haven't changed the default values and using the SDK nrf_sdh_enable_request(). the params are:

        nrf_clock_lf_cfg_t const clock_lf_cfg =
        {
            .source       = NRF_SDH_CLOCK_LF_SRC,
            .rc_ctiv      = NRF_SDH_CLOCK_LF_RC_CTIV,
            .rc_temp_ctiv = NRF_SDH_CLOCK_LF_RC_TEMP_CTIV,
            .accuracy     = NRF_SDH_CLOCK_LF_ACCURACY
        };

    should I have changed any of them?

  • I saw this post: https://devzone.nordicsemi.com/f/nordic-q-a/20136/central-address-resolution

    I see my nRF FW also has the Central Address Resolution and wondering if it is the cause of my trouble. I can't find a way to disable it. is there such a way?

    Thanks

  • I believe the central address resolution (CAR) characteristic can be disabled if you are using the latest v7.2.0 softdevice, then by adding the following to ble_stack_init() should remove the CAR (e.g. add it between nrf_sdh_ble_default_cfg_set() and nrf_sdh_ble_enable()):

        /* Exclude CAR from GAP service, but reserve the ATT Handles that will otherwise be used up by CAR. */

        cfg.gap_cfg.car_include_cfg.include_cfg = BLE_GAP_CHAR_INCL_CONFIG_EXCLUDE_WITH_SPACE;

        err_code = sd_ble_cfg_set(BLE_GAP_CFG_CAR_INCL_CONFIG, &cfg, ram_start);

        APP_ERROR_CHECK(err_code);

  • Thanks for the response,

    This change made pm_conn_secure() return NRF_ERROR_INTERNAL.

    digging deeper I see I get it because of this error:  NRF_ERROR_NOT_SUPPORTED from sd_ble_gap_authenticate().

     * @retval ::NRF_ERROR_NOT_SUPPORTED Setting of sign or link fields in @ref ble_gap_sec_kdist_t not supported.
     *                                   Distribution of own Identity Information is only supported if the Central
     *                                   Address Resolution characteristic is configured to be included or
     *                                   the Softdevice is configured to support peripheral roles only.
     *                                   See @ref ble_gap_cfg_car_incl_cfg_t and @ref ble_gap_cfg_role_count_t.

    This means I have to have CAR to be central? is there no way to be central without CAR?

  • You should erase all peer manager bonds and re-bond before doing this change. But if you still get an error, then you are right, that the central require this (I believe central require this, but it's optional for a peripheral).

    I don't think CAR is related to your problem.

    Kenneth

  • Thanks for your help,

    I tried the same flow (connect, bond, discovery, indicate enable, read/write) with BT900 and it does work with Android 9+. The BT900 doesn't use CAR, that's why i started suspecting it.

    From the reading of this and this posts, I'm assuming the new android doesn't clear the attribute cache. And only a reset does that. so I think the only way for me to solve this is to change the app on the android to clear the cache after every disconnect.

Reply
  • Thanks for your help,

    I tried the same flow (connect, bond, discovery, indicate enable, read/write) with BT900 and it does work with Android 9+. The BT900 doesn't use CAR, that's why i started suspecting it.

    From the reading of this and this posts, I'm assuming the new android doesn't clear the attribute cache. And only a reset does that. so I think the only way for me to solve this is to change the app on the android to clear the cache after every disconnect.

Children
No Data
Related