使用软件平台: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
",4);
}
else
{
usb_send_bytes((uint8_t *)"Error
",7);
}
}
}
问题:udi_cdc_read_buf(usbReceiveBuffer,usbReveiveBytes);接收错误,上述代码,我发送“ABCD”返回Error,发送“ ABCD”则返回OK,不知道为什么,库文件没有改动过,谁遇到过帮忙看看,谢谢1
此帖出自
小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>