WCH沁恒单片机
直播中

赵辉

12年用户 853经验值
私信 关注
[问答]

使用CH573的USB CDC串口,波特率数据每次都会变化是怎么回事?

使用CH573的USB CDC串口,串口可以通讯,数据上下行正常。但是每次打开串口都会下发两次SET_LINE_CODING,数据还不一样,我抓到的打印信息如下:

CH573>>[I/USB/CDC] set line coding dataRate : 9600 , charFormat : 0 parityType : 0 dataBits : 7
[I/USB/CDC] set line coding dataRate : 8609 , charFormat : 0 parityType : 0 dataBits : 8
[I/USB/CDC] set line coding dataRate : 9600 , charFormat : 0 parityType : 0 dataBits : 7
[I/USB/CDC] set line coding dataRate : 8609 , charFormat : 0 parityType : 0 dataBits : 8
第一次的波特率是9600 第二次这个8609是怎么回事? 前面的只有波特率是正常的,后面这次波特率不对 其他的都是正确的。



部分代码如下:

// endpoint0 out
case UIS_TOKEN_OUT:
{
LOG_D("endpoint0 out -> len = %d", R8_USB_RX_LEN);
len = R8_USB_RX_LEN;
/* 类请求 且是 设置linecodeing*/
if (SetupReqCode == SET_LINE_CODING)
{
if (RB_U_TOG_OK)
{
Line_Coding.dwDTERate = *(uint32_t *)pEP0_DataBuf;
Line_Coding.bCharFormat = pEP0_DataBuf[4];
Line_Coding.bParityType = pEP0_DataBuf[5];
Line_Coding.bDataBits = pEP0_DataBuf[6];
LOG_I("set line coding dataRate : %ld , charFormat : %d parityType : %d dataBits : %d", Line_Coding.dwDTERate, Line_Coding.bCharFormat, Line_Coding.bParityType, Line_Coding.bDataBits);
R8_UEP0_T_LEN = 0;
R8_UEP0_CTRL |= UEP_R_RES_ACK | UEP_T_RES_ACK; // 准备上传0包
}
}
else
{
R8_UEP0_T_LEN = 0;
R8_UEP0_CTRL |= UEP_R_RES_ACK | UEP_T_RES_NAK; //状态阶段,对IN响应NAK
}
R8_UEP0_CTRL ^= RB_UEP_R_TOG; //同步标志位翻转
}
break;

回帖(1)

郑盼

2022-9-2 09:58:14
CH573_CDC_OK.rar
可以参考一下CH573_CDC压缩包,你的调试环境和复现步骤可否详细叙述。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分