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

  • My device via UART send data to NRF52832,NRF52832 relay the data to slave, the packet size is 20 bytes, send continuous。device via UART send to 52832, the 52832 relay the data to slave success, then replay "SEND OK" via UART to device, then device send next packet, but sometimes ,the 53832 restart, no error watched , use RTT Viewer, not watching any error. 

    I'm use a  watchdog , use hardware timer to feed dog, when 52832 restart , the stack look likes not scheduling, so the dog not feed.

  • Now I am really confused as of what device that randomly resets, what device that isn't able to send the packet and all that.

    Do you use 2 or 3 nRFs? There are only two, right? One master and one slave? What device receives the NRF_ERROR_INVALID_STATE? And what function returns that?

  • have two NRF52832,the host nrf52832 reset. my device via uart send data to host 52832, host 52832 send the data to slave, when host sent success to slave, host 52832 reply "SEND OK"  to my device, my device send next packet data. 

Reply Children
Related