Hello, I am using the latest version of pc-ble-driver combined with a pca10040 and I am attempting to write large data packets (200 bytes) to a peripheral. I compiled the connectivity firmware myself and am using sofdevice version 5.
I keep getting an error whenever I attempt to write a 200 byte data buffer to a characteristic. The softdevice status handler spits out the error:
Status: 4, message: Error sending packet to target. Code: 0x802a
Im not sure what I am doing wrong but here are the things I have done to try and enable this:
1. I firstly set the ble config to support larger mtu:
ble_cfg.conn_cfg.conn_cfg_tag = BLE_CFG_TAG; ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu = 251; err = sd_ble_cfg_set(m_adapter, BLE_CONN_CFG_GATT, &ble_cfg, ram_start);
2. I update the mtu for a peripheral using the following function. Note Peripheral is a custom class to represent a connection.
uint32_t Peripheral::update_mtu(uint16_t mtu, on_mtu_cb_t cb)
{
if (m_att_mtu > mtu) {
return NRF_ERROR_DATA_SIZE;
}
m_att_mtu = mtu;
m_mtu_cb = cb;
return sd_ble_gattc_exchange_mtu_request(Adapter::Get(), m_conn_handle, mtu);
}
3. I wait for the mtu response event and end up calling another function in the Peripheral class.
/** The parameter to this function comes from the ble event.
* p_ble_evt->evt.gattc_evt.params.exchange_mtu_rsp.server_rx_mtu is passed.
*/
void Peripheral::on_mtu_exchange(uint16_t server_rx_mtu)
{
m_att_mtu = std::min(m_att_mtu, server_rx_mtu);
m_att_mtu = std::max(m_att_mtu, (uint16_t)BLE_GATT_ATT_MTU_DEFAULT);
if (m_mtu_cb) {
m_mtu_cb(this, m_att_mtu);
}
}
4. Once the mtu has been exchanged, I then attempt to do the write.
uint8_t data[200];
for (uint8_t i = 0; i < sizeof(data); i++) {
data[i] = i;
}
uint16_t len = sizeof(data);
ble_gattc_write_params_t write_params;
memset(&write_params, 0x00, sizeof(write_params));
write_params.handle = m_char.handle_value;
write_params.write_op = BLE_GATT_OP_WRITE_CMD;
write_params.p_value = data;
write_params.len = len;
return sd_ble_gattc_write(Adapter::Get(), m_conn_handle, &write_params);
The p_ble_gattc_evt->params.exchange_mtu_rsp.server_rx_mtu from the mtu exchange is always 247 (which is expected). But for some reason the write always results in an error. The weirdest part of it all is that if I change the data length to something smaller like 40, which is still higher than the default mtu, then the write command goes without a problem.
Am I doing something wrong here or maybe missing a step?