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

  • I see in nRF connect app that everything works fine with notify, but I must use indicate for the app I want to work with. to enable indicate I do this:

    ret_code_t nrf_ble_gattc_c_enable_indication(ble_nus_c_t * p_ble_nus_c, bool indication_enable)
    {
        nrf_ble_gq_req_t cccd_req;
        uint8_t          cccd[BLE_CCCD_VALUE_LEN];
        uint16_t         cccd_val = (indication_enable) ? BLE_GATT_HVX_INDICATION : 0;
    
        memset(&cccd_req, 0, sizeof(nrf_ble_gq_req_t));
    
        cccd[0] = LSB_16(cccd_val);
        cccd[1] = MSB_16(cccd_val);
    
        cccd_req.type                        = NRF_BLE_GQ_REQ_GATTC_WRITE;
        cccd_req.error_handler.cb            = gatt_error_handler;
        cccd_req.error_handler.p_ctx         = p_ble_nus_c;
        cccd_req.params.gattc_write.handle   = p_ble_nus_c->handles.nus_tx_cccd_handle;
        cccd_req.params.gattc_write.len      = BLE_CCCD_VALUE_LEN;
        cccd_req.params.gattc_write.offset   = 0;
        cccd_req.params.gattc_write.p_value  = cccd;
        cccd_req.params.gattc_write.write_op = BLE_GATT_OP_WRITE_REQ;
        cccd_req.params.gattc_write.flags    = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE;
    
    
        return nrf_ble_gq_item_add(p_ble_nus_c->p_gatt_queue, &cccd_req, p_ble_nus_c->conn_handle);
    }

    and I do see in the nRF connect that indicate enabled, but again, no BLE_GATTC_EVT_HVX event is triggered. am I missing something in the enabling process?

  • 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

Related