CH376做主机与CH340通信,数据不对

我用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( );

}


你的程序结构有点混乱,在获取完设备配置描述符后穿插一个往缓冲区写数据,接着又发自动配置命令,然后又启动端点2传输。此时,之前你往缓冲区写的数据早就被自动配置命令给冲掉了。另外,往340发串口数据之前你还没有发类命令(配置串口数据位、波特率等)。


只有登录才能回复,可以选择微信账号登录