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

USBD CDC ACM can't get one byte

I use the example usbd_ble_uart with SDK_15.3.0. I need to send any byte received from the terminal via BLE. Do not wait until the buffer is full or the end of line character arrives. Here is a test example:

case APP_USBD_CDC_ACM_USER_EVT_RX_DONE:
{
char m_rx_buffer[256];
ret_code_t ret;

do
{


/*Setup next transfer*/
ret = app_usbd_cdc_acm_read_any(&m_app_cdc_acm, m_rx_buffer, sizeof(m_rx_buffer));

}while(ret == NRF_SUCCESS);

//----------------------------------------------------------------------
char cdc_data[256];
sprintf(cdc_data, "data: %s \n", m_rx_buffer);
app_usbd_cdc_acm_write(&m_app_cdc_acm, cdc_data, strlen(cdc_data));
memset(cdc_data, 0x00, 256);
memset(m_rx_buffer, 0x00, 256);
//----------------------------------------------------------------------
break;
}

When using the app_usbd_cdc_acm_read_any function in the APP_USBD_CDC_ACM_USER_EVT_RX_DONE interrupt, not all bytes are read. At first, everything is read, except for the first byte:

tx: test string

rx: est string

If you transfer more bytes, then I get a piece of the previous message:

tx: 12345

rx: hellow

tx: save

rx: hellow

Perhaps an error occurs in the internal buffer? However, there is no such problem on SDK_14.0.0. All the bytes that I sent, I get completely. In these two SDKs, the file structure is different. Maybe you can transfer the library to work with USB-CDC from SDK_14.0.0? Or how to make it correct to receive bytes separately in SDK_15.3.0?

Related