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
  • So, what error did you encounter? Did it print anything in the log before you commented out the printf() calls?

    My guess is that you saw the NRF_ERROR_INVALID_PARAM or NRF_ERROR_DATA_SIZE? You need to keep the length shorter than the MTU of the connection. If the array that you need to send is larger than this, you should split it into several packets that are small enough for you to send, and then put it back together on the other side.

    Best regards,

    Edvin

Reply
  • So, what error did you encounter? Did it print anything in the log before you commented out the printf() calls?

    My guess is that you saw the NRF_ERROR_INVALID_PARAM or NRF_ERROR_DATA_SIZE? You need to keep the length shorter than the MTU of the connection. If the array that you need to send is larger than this, you should split it into several packets that are small enough for you to send, and then put it back together on the other side.

    Best regards,

    Edvin

Children
Related