nRF52833 increasing att mtu data length

hello,

I Have two nRF52833 that I have communicating over BLE. I am using soft device S140. I have my data packets use the default data length maximum of 20 bytes. I am trying to configure it such that data packets have more then 20 bytes. 

I call sd_ble_gap_data_length_update to set data length to 230 bytes. I do the following:

ble_gap_data_length_params_t const dlp =
    {
        .max_rx_octets  = 230,
        .max_tx_octets  = 230,
        .max_rx_time_us = BLE_GAP_DATA_LENGTH_AUTO,
        .max_tx_time_us = BLE_GAP_DATA_LENGTH_AUTO,
    };

    ble_gap_data_length_limitation_t dll = {0};

    ret_code_t err_code = sd_ble_gap_data_length_update(conn_handle, &dlp, &dll);
both peripheral and central print the following, as part of on_data_length_update_evt. I assume this means that the att mtu is now set to 230 bytes on each side.
<debug> nrf_ble_gatt: Data length updated to 230 on connection 0x3.
<debug> nrf_ble_gatt: max_rx_octets: 230
<debug> nrf_ble_gatt: max_tx_octets: 230
<debug> nrf_ble_gatt: max_rx_time: 2120
<debug> nrf_ble_gatt: max_tx_time: 2120 



latter I call sd_ble_gatts_value_set to fill the data packet with my data. 

gattsValue.len = 40;
gattsValue.offset = 0;
gattsValue.p_value ="character array of 40 bytes...";


errCode = sd_ble_gatts_value_set(BLE_CONN_HANDLE_INVALIDntAttHandle, &gattsValue);


when I do this I get the error [NRF_ERROR_DATA_SIZE].



I am doing something wrong and I am not sure what. have I configured something incorrectly? 


thanks


  • Hi,

    I assume you use the SoftDevice Handler (SDH) library which is used in the examples? If os, you should adjust a few parameters in sdk_config.h:

    • NRF_SDH_BLE_GAP_DATA_LENGTH
    • NRF_SDH_BLE_GATT_MAX_MTU_SIZE
    • NRF_SDH_BLE_GAP_EVENT_LENGTH

    You can refer to examples/ble_peripheral/ble_app_uart/pca10056/s140/config/sdk_config.h for an example.

  • thanks for the response.
    this is my settup:
    NRF_SDH_BLE_GAP_DATA_LENGTH = 244
    NRF_SDH_BLE_GATT_MAX_MTU_SIZE = 244
    NRF_SDH_BLE_GAP_EVENT_LENGTH = 400

    I get the message in the debug terminal:
    <debug> nrf_ble_gatt: ATT MTU updated to 244 bytes on connection 0x3 (response).

    then when I call sd_ble_gatts_value_set passing a .len of 40 I still get the following error:
    <error> app: ERROR 12 [NRF_ERROR_DATA_SIZE] at C:\Users\...

  • Hi,

    I see. The only other thing I can think of is that the maximum length for the characteristic is lower? Which max_len was used when you added the characteristic with sd_ble_gatts_characteristic_add() or indirectly with characteristic_add()?

  • I figured out what I was doing wrong, and I wanted to share incase it is useful to anyone. my issue was that when I called characteristic_add I passed in a .max_len of 20. 

    both peripheral and central agreed that max length would be 244 based on the messaging I saw.

    but this is not the only thing sd_ble_gatts_value_set checks before returning [NRF_ERROR_DATA_SIZE]. it also checks .max_len value set by characteristic_add.


    in summary to get packets with data of more than 20bytes:

    set these define:
    NRF_SDH_BLE_GAP_DATA_LENGTH = 244
    NRF_SDH_BLE_GATT_MAX_MTU_SIZE = 244
    NRF_SDH_BLE_GAP_EVENT_LENGTH = 400

    AND
    pass characteristic_add .max_len of desired data value.

    doing all this will let you send packets of more then 20bytes.

    thanks einar for the help.

     

Related