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

Long BLE Write Error

Hi,

I am trying to write 64 bytes to a characteristic as a client and am getting the error NRF_ERROR_DATA_SIZE. The infocenter is not very helpful at indicating where the issue of size may originate from. I control both the peripheral and central so I am initialising the characteristic on the peripheral like so:

ble_gatts_attr_t    attr_char_value;
memset(&attr_char_value, 0, sizeof(ble_gatts_attr_t));        
attr_char_value.p_uuid      = &char_uuid;
attr_char_value.p_attr_md   = &attr_md;

// Set characteristic length in number of bytes
attr_char_value.max_len     = SIGNED_LEN_BYTES;
attr_char_value.init_len    = SIGNED_LEN_BYTES;
attr_char_value.p_value     = 0;

and I write to it on the central like so:

ble_gattc_write_params_t ble_gattc_write_params;
uint8_t write_handle;
write_handle = m_serv.signed_char_handles.value_handle;
	
uint8_t p_write[SIGNED_LEN_BYTES];
	
memcpy(p_write, p_signed_write, SIGNED_LEN_BYTES);
	
ble_gattc_write_params.write_op		= BLE_GATT_OP_WRITE_REQ;
ble_gattc_write_params.flags		= BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE;
ble_gattc_write_params.handle		= write_handle;
ble_gattc_write_params.offset		= 0;
ble_gattc_write_params.len			= SIGNED_LEN_BYTES;   	
ble_gattc_write_params.p_value		= p_write;
	
ret_code_t err_code = sd_ble_gattc_write(m_conn_handle_central, &ble_gattc_write_params);
APP_ERROR_CHECK(err_code);

Any advice as to where the error might be originating from would be much appreciated.

I am using the nRF52832 with SD s132 v4.0.2 and SDK13.0.0 on both sides.

Thanks,

Parents
  • Look at functions sd_ble_gattc_exchange_mtu_request and sd_ble_gap_data_length_update. By default you can write 20 bytes of data in single write. You have to negotiate mtu size with your peer with sd_ble_gattc_exchange_mtu_request. Both peers will choose the smallest size supported by both sides of connection.

  • Hi Andrzej,

    I am trying to negotiate MTU size with my peer but with no luck.

    I am calling the following immediately upon connection:

    err_code = sd_ble_gattc_exchange_mtu_request(p_ble_evt->evt.gap_evt.conn_handle, NRF_BLE_GATT_MAX_MTU_SIZE);
    APP_ERROR_CHECK(err_code);
    

    but I am getting the error NRF_ERROR_INVALID_PARAM and cannot work out why I am getting this error?

    In my sdk_config.h file I am defining the following:

    #define NRF_BLE_GATT_MAX_MTU_SIZE 247
    

    and am initialising in my ble_stack_init() function like so:

    ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu = NRF_BLE_GATT_MAX_MTU_SIZE;
    
Reply
  • Hi Andrzej,

    I am trying to negotiate MTU size with my peer but with no luck.

    I am calling the following immediately upon connection:

    err_code = sd_ble_gattc_exchange_mtu_request(p_ble_evt->evt.gap_evt.conn_handle, NRF_BLE_GATT_MAX_MTU_SIZE);
    APP_ERROR_CHECK(err_code);
    

    but I am getting the error NRF_ERROR_INVALID_PARAM and cannot work out why I am getting this error?

    In my sdk_config.h file I am defining the following:

    #define NRF_BLE_GATT_MAX_MTU_SIZE 247
    

    and am initialising in my ble_stack_init() function like so:

    ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu = NRF_BLE_GATT_MAX_MTU_SIZE;
    
Children
No Data
Related