您好
开发特定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);
}
您好
开发特定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);
}
举报