<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Wrong data in the receive buffer USB CDC</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/43308/wrong-data-in-the-receive-buffer-usb-cdc</link><description>Hello! I took the example of &amp;quot;usbd_cdc_acm&amp;quot; and added a receive and transmit buffer. The data from the receive buffer is sent back. It turned out that the first byte is written to the end of the previous reception. How do I get the correct packet in the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 14 Feb 2019 08:28:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/43308/wrong-data-in-the-receive-buffer-usb-cdc" /><item><title>RE: Wrong data in the receive buffer USB CDC</title><link>https://devzone.nordicsemi.com/thread/171028?ContentTypeID=1</link><pubDate>Thu, 14 Feb 2019 08:28:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f54d40c-bd40-4984-a905-73754fda46be</guid><dc:creator>Valery</dc:creator><description>&lt;p&gt;I dealt with this question, I made same &amp;quot;usbd_ble_uart_freertos&amp;quot; example. Thank you very much!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wrong data in the receive buffer USB CDC</title><link>https://devzone.nordicsemi.com/thread/169702?ContentTypeID=1</link><pubDate>Wed, 06 Feb 2019 11:57:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f36fd41-149b-4557-b6b4-928457628b6d</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You should take a look at how we do the RX buffer handling in the&amp;nbsp;usbd_ble_uart example. But instead of sending the data over BLE as done in that example, you send it back over USB using&amp;nbsp;app_usbd_cdc_acm_write().&lt;/p&gt;
&lt;p&gt;Snippet:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static char m_cdc_data_array[256];
#define ENDLINE_STRING &amp;quot;\r\n&amp;quot;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In your cdc_acm_user_ev_handler:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;case APP_USBD_CDC_ACM_USER_EVT_RX_DONE:
        {

            ret_code_t ret;
            static uint8_t index = 0;
            index++;
            NRF_LOG_INFO(&amp;quot;Bytes waiting: %d&amp;quot;, app_usbd_cdc_acm_bytes_stored(p_cdc_acm));
            do
            {
                if ((m_cdc_data_array[index - 1] == &amp;#39;\n&amp;#39;) ||
                    (m_cdc_data_array[index - 1] == &amp;#39;\r&amp;#39;) ||
                    (index &amp;gt;= (255)))
                {
                    if (index &amp;gt; 1)
                    {
                        
                        NRF_LOG_DEBUG(&amp;quot;Ready to send data&amp;quot;);
                        NRF_LOG_HEXDUMP_DEBUG(m_cdc_data_array, index);

                            uint16_t length = (uint16_t)index;
                            if (length + sizeof(ENDLINE_STRING) &amp;lt; 255)
                            {
                                memcpy(m_cdc_data_array + length, ENDLINE_STRING, sizeof(ENDLINE_STRING));
                                length += sizeof(ENDLINE_STRING);
                            }


                             ret = app_usbd_cdc_acm_write(&amp;amp;m_app_cdc_acm, m_cdc_data_array, length);

                    }

                    index = 0;
                }

                /*Get amount of data transferred*/
                size_t size = app_usbd_cdc_acm_rx_size(p_cdc_acm);
                NRF_LOG_DEBUG(&amp;quot;RX: size: %lu char: %c&amp;quot;, size, m_cdc_data_array[index - 1]);

                /* Fetch data until internal buffer is empty */
                ret = app_usbd_cdc_acm_read(&amp;amp;m_app_cdc_acm,
                                            &amp;amp;m_cdc_data_array[index],
                                            1);
                if (ret == NRF_SUCCESS)
                {
                    index++;
                }
            }
            while (ret == NRF_SUCCESS);


            bsp_board_led_invert(LED_CDC_ACM_RX);
            break;
        }&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>