我根据你们的ch372上位机自己也编了一个上位机,增加了一个端点1的下传部分,在上位机部分可以通过两个端点传输数据到单片机,但是再从单片机返回数据到上位机则只能向USB端点2的发送缓冲区写入数据块或只能向USB端点1的发送缓冲区写入数据块,不能端点2接收的数据写到端点2的发送缓冲区,而端点1写到端点1的发送缓冲区,在上位机部分端点2的能显示,而端点1的不能显示,希望指点一下,谢谢。下面是源程序,是在例子程序中稍微改了一下。
void mCh375Interrupt( ) interrupt 0 using 1 { unsigned char InterruptStatus; unsigned char i, length; unsigned char data buffer[ 64 ]; CH375_WR_CMD_PORT( CMD_GET_STATUS ); InterruptStatus = CH375_RD_DAT_PORT( ); switch ( InterruptStatus ) {
case USB_INT_EP2_OUT: { CH375_WR_CMD_PORT( CMD_RD_USB_DATA ); length = CH375_RD_DAT_PORT( ); for ( i = 0; i < length; i ++ ) buffer[ i ] = CH375_RD_DAT_PORT( ); //CH375_WR_CMD_PORT( CMD_WR_USB_DATA7 ); CH375_WR_CMD_PORT( CMD_WR_USB_DATA5 ); CH375_WR_DAT_PORT( length ); for ( i = 0; i < length; i ++ ) CH375_WR_DAT_PORT( buffer[ i ] ); //P1=buffer[0]; // 测试电压 break; }
case USB_INT_EP1_OUT: { CH375_WR_CMD_PORT( CMD_RD_USB_DATA ); length = CH375_RD_DAT_PORT( ); for ( i = 0; i < length; i ++ ) buffer[ i ] = CH375_RD_DAT_PORT( ); //CH375_WR_CMD_PORT( CMD_WR_USB_DATA7 ); CH375_WR_CMD_PORT( CMD_WR_USB_DATA5 ); CH375_WR_DAT_PORT( length ); for ( i = 0; i < length; i ++ ) CH375_WR_DAT_PORT( buffer[ i ] ); P1=buffer[0]; // 测试电压 break; }
case USB_INT_EP2_IN: { CH375_WR_CMD_PORT( CMD_UNLOCK_USB ); break; } case USB_INT_EP1_IN: { CH375_WR_CMD_PORT( CMD_UNLOCK_USB ); break; } default: { CH375_WR_CMD_PORT( CMD_UNLOCK_USB ); break; } } }
main( ) { Delay50ms( ); CH375_Init( ); EA = 1; while ( 1 ); }