<?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>USB missing byte</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/85156/usb-missing-byte</link><description>Hi, 
 I am developing my own vendor specific USB device with 2 interfaces (data and debug) and 2 endpoints(in and out) each. I based my class on the cdc_acm class. 
 So far most of it works. The only problem is, when I send more than 1 byte at a time</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 01 Mar 2022 09:55:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/85156/usb-missing-byte" /><item><title>RE: USB missing byte</title><link>https://devzone.nordicsemi.com/thread/355473?ContentTypeID=1</link><pubDate>Tue, 01 Mar 2022 09:55:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:50844a98-e172-4919-b15b-d35ca2cfeea3</guid><dc:creator>JoEi</dc:creator><description>&lt;p&gt;Hi Hung Bui,&lt;/p&gt;
&lt;p&gt;thanks for the fast reply.&lt;/p&gt;
&lt;p&gt;I found the error yesterday evening and it is exactly the same error you mentioned.&lt;br /&gt;It&amp;#39;s funny. I searched for &amp;quot;1 byte missing usb&amp;quot; but didn&amp;#39;t&amp;nbsp;find the case you posted and all the other cases I found were similar but ultimately different.&lt;/p&gt;
&lt;p&gt;Kind regards&lt;br /&gt;Johannes&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USB missing byte</title><link>https://devzone.nordicsemi.com/thread/355453?ContentTypeID=1</link><pubDate>Tue, 01 Mar 2022 08:52:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03596409-46be-49b0-9435-a645af99d236</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Johannes,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you search for &amp;quot;1 byte missing usb devzone&amp;quot;&amp;nbsp; you can find many cases on devzone asked about this. It&amp;#39;s a bit confusing in the way the function&amp;nbsp;app_usbd_cdc_acm_read() was designed.&amp;nbsp;&lt;br /&gt;I would suggest to have a look &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/69431/usbd_cdc_acm-1st-byte-missing-on-second-message-sent-when-messages-are-greater-than-64-bytes"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As I explained in the case, quoted:&lt;br /&gt;===========&lt;/p&gt;
&lt;p&gt;&lt;em&gt;As Dmitry already explained to you&amp;nbsp;app_usbd_cdc_acm_read() doesn&amp;#39;t read the byte(s) immediately, it only provide a buffer for the next &amp;quot;byte&amp;quot; (or bytes depends on the buffer size you provided) to come.&amp;nbsp;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;So in your case you can call&amp;nbsp;app_usbd_cdc_acm_read() with the buffer size of 64 bytes. See&amp;nbsp;APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN event in the cdc example.&amp;nbsp;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;When you receive&amp;nbsp;APP_USBD_CDC_ACM_USER_EVT_RX_DONE event this meant that there are 64 bytes already in the buffer and you can start using it. You don&amp;#39;t need to call&amp;nbsp;app_usbd_cdc_acm_read() again to read them. You call&amp;nbsp;app_usbd_cdc_acm_read() again to prepare the buffer for the next 64 bytes.&amp;nbsp;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;And since&amp;nbsp;app_usbd_cdc_acm_read() can handle double buffer, you can call&amp;nbsp;app_usbd_cdc_acm_read() two times with two different buffers in&amp;nbsp;APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN event. This way you have double buffer and can handle if there are more than 64 bytes comes before you can process them.&amp;nbsp;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;============&lt;/p&gt;
&lt;p&gt;I would need to see your full code and what inside your&amp;nbsp;app_usbd_dev_read_data() but as mentioned above when you call&amp;nbsp;app_usbd_cdc_acm_read() it&amp;#39;s for the next byte to come, the current byte is already in the buffer when you receive&amp;nbsp;APP_USBD_CDC_ACM_USER_EVT_RX_DONE event.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>