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,

  • 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;
    
  • I have

    #define APP_BLE_CONN_CFG_TAG            1
    
    memset(&ble_cfg, 0x00, sizeof(ble_cfg));
    ble_cfg.conn_cfg.conn_cfg_tag                 = APP_BLE_CONN_CFG_TAG;
    ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu = NRF_BLE_GATT_MAX_MTU_SIZE ;
    err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATT, &ble_cfg, ram_start);
    

    It is then essential to use APP_BLE_CONN_CFG_TAG when advertising with sd_ble_gap_adv_start or connecting with sd_ble_gap_connect

    err_code = sd_ble_gap_connect(&evt->peer_addr, &appbleScanParamsDefault,
    				&appbleConnParamsDefault, APP_BLE_CONN_CFG_TAG) ;
    
  • I have double checked this and I am doing all of those things. The define is used in advertising, connecting and initialising. Still the same error. Snippets as follows:

    Config:

    #define CONN_CFG_TAG                	1
    

    Init:

    memset(&ble_cfg, 0, sizeof(ble_cfg_t));
    ble_cfg.conn_cfg.params.gap_conn_cfg.conn_count     = PERIPHERAL_LINK_COUNT + CENTRAL_LINK_COUNT;
    ble_cfg.conn_cfg.params.gap_conn_cfg.event_length   = BLE_GAP_EVENT_LENGTH_DEFAULT;
    ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu		= NRF_BLE_GATT_MAX_MTU_SIZE;
    ble_cfg.conn_cfg.conn_cfg_tag                       = CONN_CFG_TAG;
    err_code = sd_ble_cfg_set(BLE_CONN_CFG_GAP, &ble_cfg, ram_start);
    

    Connect:

    err_code = sd_ble_gap_connect(peer_addr, &m_scan_params, &m_connection_param, CONN_CFG_TAG);
    

    Advertise:

    err_code = sd_ble_gap_adv_start(&adv_params, CONN_CFG_TAG);
    
  • When do you get NRF_ERROR_DATA_SIZE? From what function is it returned, and/or in what event do you get that error?

Related