我用CH376做主机与CH340进行USB通信,发现当发送十六进制数据:AA AA AA AA AA AA AA AA AA AA十个数据时,CH340串口输出00 00 E0 00 00 00 00 00 00九个数据,每次都是这样,请帮忙看一下,怎么收到数据不对呢,谢谢了。部分源代码如下
main()
{
RtnBool = USB_Dev_Connect_Poll();
CH376WriteHostBlock(UsbPcBuffer,10);
USBC_ISSUE_TKN_X();
}
bIs USB_Dev_Connect_Poll(void)
{
int Index;
myRtn RtnState;
u8 RtnData;
//0 系统归零,不产生SOF包
USBC_Bus_UnInit();
// 1 插入
RtnData = CH376TestConnect();
if(RtnData != USB_INT_CONNECT)
{
return bFalse;
}
USBC_Delay_1200us(20);
// 2 总线初始化
USBC_Bus_UnInit();
RtnState = USBC_Bus_Init();
if (RtnState == RTN_ERR)
{
return bFalse;
}
RtnState = USBC_GET_DEV_DESCR();
return bTrue;
}
myRtn USBC_ISSUE_TKN_X(void)
{
bIs RtnBool;
CH376SendCmdWaitInt(CMD_AUTO_SETUP);
RtnBool = CH376GetIntStatus();//返回0x14
USBC_Send_Cmd(CMD_ISSUE_TKN_X);
USBC_Send_Data(0x80);
USBC_Send_Data(0x21);
RtnBool = Wait376Interrupt();//返回0x14
}
myRtn USBC_GET_DEV_DESCR(void)
{
bIs RtnBool,Len;
USBC_Send_Cmd(CMD_GET_DESCR);
USBC_Send_Data(0x01);
RtnBool = Wait376Interrupt();//返回0x14
Len = CH376ReadBlock(&USB_DeviceDescriptor);//正常返回18个设备描述符
USBC_Send_Cmd(CMD_GET_DESCR);
USBC_Send_Data(0x02);
RtnBool = Wait376Interrupt();//返回0x14
Len = CH376ReadBlock(&USB_ConfigDescriptor);//正常返回39配置描述符
}
myRtn USBC_SET_DEV_RATE(void)
{
bIs RtnBool;
USBC_Send_Cmd(CMD_SET_USB_SPEED);
USBC_Send_Data(0x00);
}
voidCH376WriteHostBlock( PUINT8 buf, UINT8 len )
{
xWriteCH376Cmd( CMD_WR_HOST_DATA );
xWriteCH376Data( len );
if ( len )
{
do
{
xWriteCH376Data( *buf );
buf ++;
} while ( -- len );
}
xEndCH376Cmd( );
}