官方程序中有几个BUG导致只能单字节发送,用7位串口方式也有问题。查看源程序,发现有几个地方需要修改:
XXXXB->UART 没有等串口发送完,现象是只能发一个字符
void USB_To_USART_Send_Data(u8* data_buffer, u8 Nb_bytes)
{
u32 i;
for (i = 0; i < Nb_bytes; i++)
{
USART_SendData(USART1, *(data_buffer + i));
//added by dreamdive
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
}
}
XXXXol USART_Config(void)函数中,数据长度设置错误导致乱码
/*set the data type : only 8bits and 9bits is supported */
switch (linecoding.datatype)
{
case 0x07://数据长度7位
USART_XXXXXXXXXXXXXXXXART_WordLength = USART_WordLength_8b;
break;
case 0x08://数据长度8位
//USART_XXXXXXXXXXXXXXXXART_WordLength = USART_WordLength_9b;
//无较验位时用8位方式,否则用9位方式
if(XXXXXXXXXXXXXritytype==USART_Parity_No)
USART_XXXXXXXXXXXXXXXXART_WordLength = USART_WordLength_8b;
else
USART_XXXXXXXXXXXXXXXXART_WordLength = USART_WordLength_9b;
break;
default :
{
USART_Config_Default();
return (FALSE);
}
}
3.void USART_To_USB_Send_Data(void)函数中,判断错误导致用7位串口方式时UART->USB乱码
if (USART_XXXXXXXXXXXXXXXXART_WordLength == USART_WordLength_8b)
{
buffer_in[count_in] = USART_ReceiveData(USART1) & 0x7F;
}
else if (USART_XXXXXXXXXXXXXXXXART_WordLength == USART_WordLength_9b)
{
buffer_in[count_in] = USART_ReceiveData(USART1);
}
改为:
if (linecoding.datatype == 0x07)
{
buffer_in[count_in] = USART_ReceiveData(USART1) & 0x7F;
}
else
{
buffer_in[count_in] = USART_ReceiveData(USART1);
}
经测试,8位无校验/带校验和7位无校验/带校验工作全部正常。
刚刚看了ST最新官方um0424.zip,修正和我想的一样,呵呵:-).不过有个网友发现有个问题见
不知是不是中断处理的不好(我没有测试过新版的,一直在用KEIL自带的例程)。