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

How to send a big data array to slave in host mode?

a data array, length is 2048,use function "sd_ble_gattc_write", a error occurred, length less than 240, no error.

do
{。。
err_code = write_configure(m_center_handle,14,(uint8_t *)UART_RX_BUF,UART_RX_STA,0);
//printf("err:\r\n0x%x\r\n",err_code);
if ( (err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY) )
{
NRF_LOG_ERROR("Failed sending NUS message. Error 0x%x. ", err_code);
APP_ERROR_CHECK(err_code);
}
}while (err_code == NRF_ERROR_BUSY/*NRF_ERROR_RESOURCES*/);

static uint32_t write_configure(uint16_t conn_handle, uint16_t cccd_handle, uint8_t *buf,uint16_t data_len, bool enable)
{
uint16_t err_code;
// printf("%s\r\n",buf_1);
// printf("%s\r\n",buf);
ble_gattc_write_params_t const write_params =
{
.write_op = BLE_GATT_OP_WRITE_CMD,//BLE_GATT_OP_WRITE_REQ,
.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE,
.handle = cccd_handle,
.offset = 0,
.len = data_len,//sizeof(buf),
.p_value = buf
};
//err_code=sd_ble_gattc_write(conn_handle, &write_params);
//do{
err_code=sd_ble_gattc_write(conn_handle, &write_params);
//}while(err_code==NRF_ERROR_BUSY);
if(err_code!=NRF_SUCCESS)
{
//printf("w:0x%d,%d,0,e:%x\r\n",conn_handle,cccd_handle,err_code);//20210117-
}
else
{
//printf("w:0x%d,%d,1\r\n",conn_handle,cccd_handle);//20210117-
}
return err_code;//0;
}

Parents Reply
  • Does that only occur when you increase the packet length? This typically means that the connection is not fully completed yet.

    What do you mean by:

    Nordfield said:

    ble_nus_data_send

    sd_ble_gattc_write

     ble_nus_data_send() doesn't use sd_ble_gattc_write. sd_ble_gattc_write() is for centrals/masters, and ble_nus_data_send() is for peripherals/slaves.

    Best regards,

    Edvin

Children
No Data
Related