我在用串口连续发送一串数字时,第一个数总是发不出去,我用STM32F103ZE,STM32F103CB都是这样的情况,以下是代码:
USART_SendData(USART1,0x06);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
USART_SendData(USART1,0x07);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
USART_SendData(USART1,0x08);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
USART_SendData(USART1,0x09);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
USART_SendData(USART1,0x10);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
串口的初始化代码:
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate=UARTBaud;
USART_InitStructure.USART_WordLength=USART_WordLength_8b;
USART_InitStructure.USART_StopBits=USART_StopBits_1;
USART_InitStructure.USART_Parity=USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1,USART_IT_RXNE, ENABLE);
USART_Cmd(USART1, ENABLE);
发完之后的现象:
我是以十六进制接收的,但总是缺少第一个数0x06 |