使用软件平台:AtmelStudio7,ASF版本3.35.1 ,模块USB device CDC
硬件Atmel SAMDA1
实现功能:USB Device收发
代码:
udc_start();
// The main loop manages only the power mode
// because the USB management is done by interrupt
while(true)
{
if(udi_cdc_is_rx_ready())
{ // USB有数据送过来
/* 接收PC送来的数据 */
usbReveiveBytes = udi_cdc_get_nb_received_data();
memset(usbReceiveBuffer,0,200); // 缓冲区清零
udi_cdc_read_buf(usbReceiveBuffer,usbReveiveBytes);
/* 判断数据 */
if(usbReceiveBuffer[0] == 'A'
&& usbReceiveBuffer[1] == 'B'
&& usbReceiveBuffer[2] == 'C'
&& usbReceiveBuffer[3] == 'D')
{
usb_send_bytes((uint8_t *)"OK\r\n",4);
}
else
{
usb_send_bytes((uint8_t *)"Error\r\n",7);
}
}
}
问题:udi_cdc_read_buf(usbReceiveBuffer,usbReveiveBytes);接收错误,上述代码,我发送“ABCD”返回Error,发送“ ABCD”则返回OK,不知道为什么,库文件没有改动过,谁遇到过帮忙看看,谢谢1
你好,我司是microchip代理商,我司有专门的FAE帮您解决,有需要请联系我13798245017