CH554使用ch554_uart_2_uart.rar进行usb串口透传,怎么操作FT232的USB转串口芯片,案例中只有CH34X,PL2303,CP210x。怎么添加FT232的支持?谢谢 了
如果在原例程上修改添加更好不过了。
CH554使用ch554_uart_2_uart.rar进行usb串口透传,怎么操作FT232的USB转串口芯片,案例中只有CH34X,PL2303,CP210x。怎么添加FT232的支持?谢谢 了
如果在原例程上修改添加更好不过了。
您好
开发特定USB设备的主机时,可以使用一些上位机软件抓取USB设备和上位机的通信,然后使用MCU模拟这个PC的通信过程。
在枚举获取描述符部分,FT232和其他设备一样,在设置波特率等方面可能不同。这边提供一段FT232波特率等配置的代码,按照这样的顺序发送SETUP包,就是配置FT232的过程,希望能有所帮助。
unsigned char Baud_buf1_5[8]={0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char Baud_buf6[8]={0x02,0x01,0x00,0x00,0x81,0x00,0x00,0x00}; unsigned char Baud_buf7[8]={0x40,0x09,0x10,0x00,0x00,0x00,0x00,0x00}; unsigned char Baud_buf8[8]={0xc0,0x05,0x00,0x00,0x00,0x00,0x02,0x00}; //无 unsigned char Baud_buf9[8]={0x40,0x04,0x07,0x00,0x00,0x00,0x00,0x00}; //无 unsigned char Baud_buf10[8]={0x40,0x01,0x01,0x01,0x00,0x00,0x00,0x00}; unsigned char Baud_buf11[8]={0x40,0x01,0x02,0x02,0x00,0x00,0x00,0x00}; unsigned char Baud_buf12[8]={0x40,0x02,0x00,0x00,0x00,0x00,0x00,0x00}; //无 //unsigned char Baud_buf13[8]={0x40,0x03,0xc4,0x09,0x00,0x00,0x00,0x00}; unsigned char Baud_buf14[8]={0x40,0x03,0xc4,0x09,0x00,0x00,0x00,0x00}; //特特率 unsigned char Baud_buf15[8]={0x40,0x01,0x02,0x02,0x00,0x00,0x00,0x00}; //无 unsigned char Baud_buf16[8]={0x40,0x01,0x01,0x01,0x00,0x00,0x00,0x00}; //无 unsigned char Baud_buf17[8]={0x40,0x04,0x07,0x02,0x00,0x00,0x00,0x00}; //设置数据位、停止位、校验位等 unsigned char Baud_buf18[8]={0x40,0x02,0x00,0x00,0x00,0x00,0x00,0x00}; //流控设置 unsigned char Baud_buf19[8]={0x40,0x06,0x00,0x00,0x00,0x00,0x00,0x00}; //配置FT232R波特率 void FT232R_Baud_Config( UINT32 baud ) { unsigned char s=0,ix; unsigned short int len; FT232R_Baud_Set(Baud_buf1_5); FT232R_Baud_Set(Baud_buf1_5); FT232R_Baud_Set(Baud_buf6); FT232R_Baud_Set(Baud_buf7); FT232R_Baud_Set(Baud_buf8); FT232R_Baud_Set(Baud_buf10); FT232R_Baud_Set(Baud_buf11); FT232R_Baud_Set(Baud_buf12); baud = 10*3000000/baud; //分频 baud = (baud+5)/10; //做四舍五入 Baud_buf14[2]=baud&0xff; Baud_buf14[3]=(baud>>8)&0xff; Baud_buf14[4]=(baud>>16)&0xff; FT232R_Baud_Set(Baud_buf14);//这一次的波特率 FT232R_Baud_Set(Baud_buf17); FT232R_Baud_Set(Baud_buf18); FT232R_Baud_Set(Baud_buf19); }
你好,根据你提供的数组,我添加到CH554_uart2uart的工程,当前实现了FT232插入时检测设备,并且能接收一段我开发板发送的字符,但是当开发板已经发送结束了,CH554还是一直接收到FT232发送的东西,并且串口打印是乱码的。
下面是工程中我添加的FT232设置波特率部分函数
UINT8 FT232_Baud_Config(UINT32 baud) { UINT8 s; UINT16 tmp; TxBuffer[0] = 0x40; TxBuffer[1] = 0x00; TxBuffer[2] = 0x00; TxBuffer[3] = 0x00; TxBuffer[4] = 0x00; TxBuffer[5] = 0x00; TxBuffer[6] = 0x00; TxBuffer[7] = 0x00; s = HostCtrlTransfer( NULL, NULL ); TxBuffer[0] = 0x40; TxBuffer[1] = 0x00; TxBuffer[2] = 0x00; TxBuffer[3] = 0x00; TxBuffer[4] = 0x00; TxBuffer[5] = 0x00; TxBuffer[6] = 0x00; TxBuffer[7] = 0x00; s = HostCtrlTransfer( NULL, NULL ); TxBuffer[0] = 0x02; TxBuffer[1] = 0x01; TxBuffer[2] = 0x00; TxBuffer[3] = 0x00; TxBuffer[4] = 0x81; TxBuffer[5] = 0x00; TxBuffer[6] = 0x00; TxBuffer[7] = 0x00; s = HostCtrlTransfer( NULL, NULL ); TxBuffer[0] = 0x40; TxBuffer[1] = 0x09; TxBuffer[2] = 0x10; TxBuffer[3] = 0x00; TxBuffer[4] = 0x00; TxBuffer[5] = 0x00; TxBuffer[6] = 0x00; TxBuffer[7] = 0x00; s = HostCtrlTransfer( NULL, NULL ); TxBuffer[0] = 0xc0; TxBuffer[1] = 0x05; TxBuffer[2] = 0x00; TxBuffer[3] = 0x00; TxBuffer[4] = 0x00; TxBuffer[5] = 0x00; TxBuffer[6] = 0x02; TxBuffer[7] = 0x00; s = HostCtrlTransfer( NULL, NULL ); TxBuffer[0] = 0x40; TxBuffer[1] = 0x01; TxBuffer[2] = 0x01; TxBuffer[3] = 0x01; TxBuffer[4] = 0x00; TxBuffer[5] = 0x00; TxBuffer[6] = 0x00; TxBuffer[7] = 0x00; s = HostCtrlTransfer( NULL, NULL ); TxBuffer[0] = 0x40; TxBuffer[1] = 0x01; TxBuffer[2] = 0x02; TxBuffer[3] = 0x02; TxBuffer[4] = 0x00; TxBuffer[5] = 0x00; TxBuffer[6] = 0x00; TxBuffer[7] = 0x00; s = HostCtrlTransfer( NULL, NULL ); TxBuffer[0] = 0x40; TxBuffer[1] = 0x02; TxBuffer[2] = 0x00; TxBuffer[3] = 0x00; TxBuffer[4] = 0x00; TxBuffer[5] = 0x00; TxBuffer[6] = 0x00; TxBuffer[7] = 0x00; s = HostCtrlTransfer( NULL, NULL ); tmp=(10*3000000/baud); tmp = (tmp+5)/10; TxBuffer[0] = 0x40; TxBuffer[1] = 0x03; TxBuffer[2] = (UINT8)(tmp&0Xff); TxBuffer[3] = (UINT8)((tmp>>8)&0xff); TxBuffer[4] = (UINT8)((tmp>>16)&0xff); TxBuffer[5] = 0x00; TxBuffer[6] = 0x00; TxBuffer[7] = 0x00; s = HostCtrlTransfer( NULL, NULL ); TxBuffer[0] = 0x40; TxBuffer[1] = 0x04; TxBuffer[2] = 0x07; TxBuffer[3] = 0x02; TxBuffer[4] = 0x00; TxBuffer[5] = 0x00; TxBuffer[6] = 0x00; TxBuffer[7] = 0x00; s = HostCtrlTransfer( NULL, NULL ); TxBuffer[0] = 0x40; TxBuffer[1] = 0x02; TxBuffer[2] = 0x00; TxBuffer[3] = 0x00; TxBuffer[4] = 0x00; TxBuffer[5] = 0x00; TxBuffer[6] = 0x00; TxBuffer[7] = 0x00; s = HostCtrlTransfer( NULL, NULL ); TxBuffer[0] = 0x40; TxBuffer[1] = 0x06; TxBuffer[2] = 0x00; TxBuffer[3] = 0x00; TxBuffer[4] = 0x00; TxBuffer[5] = 0x00; TxBuffer[6] = 0x00; TxBuffer[7] = 0x00; s = HostCtrlTransfer( NULL, NULL ); return s; }
下面是用SSCOM串口工具打印的乱码信息:
求助,当前该如何修改程序?问题是出在哪里呢?
您好
使用一些上位机抓包软件可以看到,FT232在上传数据时,会默认一直上传两个字节,0x01 0x60(`),这两个字节的数据您可以省略掉,只保留后面的数据即可。
您好,我尝试着过滤数据包中的0x01和0x60,但是这样做会导致我数据包丢包,是否有可能对FT232进行设置,不要一直发送0x01和0x60这两个字符?
楼主解决了吗 工程是否可以发给我参考一下
楼主工程是否可以分享一下,邮箱个人信息保护,已隐藏
你好,请问问题解决了吗?
按照下面的操作:
会出现在接受FT232的数据时,单字节最高bit位总是为0,例如我发0x81,单片机uart口收到的就是0x01, 发0xAA,收到的就是0x2A,请问有遇到过这种情况吗?