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

sd_ble_gattc_read issue

Hello Nordic semi team, 

I am running into an issue with sd_ble_gattc_read

I have set the MTU size to 70 and I do this:

// Configure the gatt MTU size .
memset(&ble_cfg, 0, sizeof(ble_cfg));
ble_cfg.conn_cfg.conn_cfg_tag = APP_BLE_CONN_CFG_TAG;
ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu = MTU_SIZE;
err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATT, &ble_cfg, *ptr );

When I do a read using 

  er =  sd_ble_gattc_read(tenx_ble.conn_handle, tenx_ble.read_handle, 0);

I do the read using this (in interrupt)

if (p_ble_evt->header.evt_id==BLE_GATTC_EVT_READ_RSP)
{
memcpy((void*) incoming_tenx_ble_read_buffer, (void*) &p_ble_evt->evt.gattc_evt.params.read_rsp.data[0], MTU_SIZE);
tenx_ble.event= READ_SUCCESS;
}

I get only 22 bytes of data. 

Why is this sd_ble_gattc_read call returning only 22 bytes when I have told the SD that my MTU is 70 bytes?

I know in the ble header files you have defined ATT_MTU = 23, but I am not using the ATT_MTU anywhere. Is this 23 hard coded in softdevice?

Kind regards, 

Hari 

Parents
  • Hi,

    First of all, I want to mention that if you use the SDK you only need to set NRF_SDH_BLE_GATT_MAX_MTU_SIZE to what you want in sdk_config.h, and then actually setting the option (calling sd_ble_cfg_set()) is handled by the SoftDevice handler library when initializing the SoftDevice. This define is also used by the GATT module to handle GATT MTU Exchanges. And this is a key point, because only configuring the SoftDevice like you did is not enough to negotiate a higher MTU for a specific connection. For that you need to call sd_ble_gattc_exchange_mtu_request(). Howerver, if you just set NRF_SDH_BLE_GATT_MAX_MTU_SIZE, this will be handled by the GATT module automatically upon connection if you also ensure that NRF_BLE_GATT_MTU_EXCHANGE_INITIATION_ENABLED is set to 1 in sdk_config.h.

    So, in short, if you are using a recent SDK remove your code handling this and set NRF_SDH_BLE_GATT_MAX_MTU_SIZE properly to 70, and ensure that NRF_BLE_GATT_MTU_EXCHANGE_INITIATION_ENABLED is 1. Then you should automatically get a MTU of 70 provided it is supported by the peer.

  • Hello Einar, 

    Thank you very much for the quick response. Understood that another SD call is needed.

    After doing  

    er = sd_ble_gattc_exchange_mtu_request(tenx_ble.conn_handle, TENX_BLE_MTU);,

    the peer acknowledges an MTU of 70. 

    NOW, when I do a read using  

    er =  sd_ble_gattc_read(tenx_ble.conn_handle, tenx_ble.read_handle, 0);

    I get all 70 bytes in one call. 

    Thanks for your help. Much appreciated. 

Reply
  • Hello Einar, 

    Thank you very much for the quick response. Understood that another SD call is needed.

    After doing  

    er = sd_ble_gattc_exchange_mtu_request(tenx_ble.conn_handle, TENX_BLE_MTU);,

    the peer acknowledges an MTU of 70. 

    NOW, when I do a read using  

    er =  sd_ble_gattc_read(tenx_ble.conn_handle, tenx_ble.read_handle, 0);

    I get all 70 bytes in one call. 

    Thanks for your help. Much appreciated. 

Children
No Data
Related