This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF_ERROR_DATA_SIZE for writes to char with data length > 20 even after successful MTU negotiation

Hi,

I'm working with pc-ble-driver and a PCA10040 devkit.

First, the central sends a data length update:

  ble_gap_data_length_params_t params = {};
  memset(&params, 0, sizeof(ble_gap_data_length_params_t));
  params.max_tx_octets = data_len; // 27
  params.max_rx_octets = data_len; // 27 
  params.max_tx_time_us = BLE_GAP_DATA_LENGTH_AUTO; // 0
  params.max_rx_time_us = BLE_GAP_DATA_LENGTH_AUTO; // 0
  uint32_t err_code = sd_ble_gap_data_length_update(
    m_adapter,
    conn_handle,
    &params,
    NULL
  );

This returns no error (0), and on the BLE_GAP_EVT_DATA_LENGTH_UPDATE event, we see the peripheral confirm "data_len" (27) for the MTU.

Then I will attempt to write 24 bytes to a characteristic (leaving 3 extra bytes for metadata). 

 ble_gattc_write_params_t write_params;
  write_params.handle   = handle;
  write_params.len      = len;                      // 24
  write_params.p_value  = (uint8_t const * ) data;  // array of 247 elements
  write_params.write_op = write_op;
  write_params.flags    = flags;
  write_params.offset   = 0;
  uint32_t err_code = sd_ble_gattc_write(
    m_adapter, conn_handle, &write_params
  );

This will then return an err code 12 NRF_ERROR_DATA_SIZE. The only data lengths that work are 0-20.

I must be missing an important step because 20 seems to be the default maximum. But as far as I know, I've set the MTU and this still happens? 

Related