我用CH376做主機與CH340進行USB通信,發(fā)現(xiàn)當(dāng)發(fā)送十六進制數(shù)據(jù):AA AA AA AA AA AA AA AA AA AA十個數(shù)據(jù)時,CH340串口輸出00 00 E0 00 00 00 00 00 00九個數(shù)據(jù),每次都是這樣,請幫忙看一下,怎么收到數(shù)據(jù)不對呢,謝謝了。部分源代碼如下
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 系統(tǒng)歸零,不產(chǎn)生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個設(shè)備描述符?
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( );
}