Hello all,
SDK:S332 V4.0.5(related to BLE V4.2).
Platform:NRF52832.
For improving BLE data throughout, i tried to set some configurations by other guidance.
Following:
//Macros
#define NRF_BLE_GATT_MAX_MTU_SIZE 158 //GATT_MTU_SIZE_DEFAULT -> 158
#define BLE_GATT_ATT_MTU_DEFAULT 23
static void gatt_mtu_set(uint16_t att_mtu) //set att_mtu 64
{
ret_code_t err_code;
err_code = nrf_ble_gatt_att_mtu_periph_set(&m_gatt, att_mtu);
APP_ERROR_CHECK(err_code);
}
static void conn_evt_len_ext_set(bool status) //status true
{
ret_code_t err_code;
ble_opt_t opt;
memset(&opt, 0x00, sizeof(opt));
opt.common_opt.conn_evt_ext.enable = status ? 1 : 0;
err_code = sd_ble_opt_set(BLE_COMMON_OPT_CONN_EVT_EXT, &opt);
APP_ERROR_CHECK(err_code);
NRF_LOG_DEBUG("Setting connection event length extension to %u: 0x%x\r\n", status, err_code);
}
static void data_len_ext_set(bool status) //status true
{
uint8_t data_length = status ? (NRF_BLE_GATT_MAX_MTU_SIZE + 4) : (BLE_GATT_ATT_MTU_DEFAULT + 4);
(void) nrf_ble_gatt_data_length_set(&m_gatt, BLE_CONN_HANDLE_INVALID, data_length);
}
Unfortunately,when the device connceted to nRF Connect,always return "NRF_ERROR_INVALID_PARAM" printing by Logger.
When connected was established, void on_connected_evt(nrf_ble_gatt_t * p_gatt, ble_evt_t const * p_ble_evt) called, in this function,it will begin an ATT MTU exchange:
// Begin an ATT MTU exchange if necessary.
if (p_link->att_mtu_desired > p_link->att_mtu_effective)
{
NRF_LOG_DEBUG("Requesting to update ATT MTU to %u bytes on connection 0x%x.\r\n",
p_link->att_mtu_desired, conn_handle);
err_code = sd_ble_gattc_exchange_mtu_request(conn_handle, p_link->att_mtu_desired);
if (err_code == NRF_SUCCESS)
{
p_link->att_mtu_exchange_requested = true;
}
else if (err_code == NRF_ERROR_BUSY)
{
p_link->att_mtu_exchange_pending = true;
NRF_LOG_DEBUG("sd_ble_gattc_exchange_mtu_request()"
" on connection 0x%x returned busy, will retry.\r\n", conn_handle);
}
else
{
NRF_LOG_ERROR("sd_ble_gattc_exchange_mtu_request()"
" returned unexpected value 0x%x.\r\n",
err_code);
}
}
// Send a data length update request if necessary.
if (p_link->data_length_desired > p_link->data_length_effective)
{
data_length_update(conn_handle, p_gatt);
}
The logger shows:
nrf_ble_gatt:DEBUG:Requesting to update ATT MTU to 64 bytes on connection 0x0.
nrf_ble_gatt:ERROR:sd_ble_gattc_exchange_mtu_request() returned unexpected value 0x7.
nrf_ble_gatt:DEBUG:Requesting to update data length to 251 on connection 0x0.
nrf_ble_gatt:ERROR:sd_ble_gap_data_length_update() (request) on connection 0x0 returned unexpected value 0x13.
nrf_ble_gatt:INFO:nrf_ble_gatt_on_ble_evt
nrf_ble_gatt:DEBUG:Peer on connection 0x0 requested a data length of 27 bytes.
nrf_ble_gatt:DEBUG:Updating data length to 27 bytes on connection 0x0.
nrf_ble_gatt:INFO:nrf_ble_gatt_on_ble_evt
nrf_ble_gatt:DEBUG:Data length updated to 27 on connection 0x0.
nrf_ble_gatt:DEBUG:max_rx_octets: 27
nrf_ble_gatt:DEBUG:max_tx_octets: 27
nrf_ble_gatt:DEBUG:max_rx_time: 328
nrf_ble_gatt:DEBUG:max_tx_time: 328
:DEBUG:ATT MTU exchange completed. central 0xf7 peripheral 0x40
Is there any question?The setting parameters look correct,maybe other setting is must?
Thank you for you reply.
Best regards