STM32串口通讯的问题 | 在对USART初始化后,每次上电发送的第一个数据总没有,后续的数据全部正常,是否还需要对哪个标志位进行配置呢?
初始化代码
/* USART5 mode config */
USART_InitStructure.USART_BaudRate = 9600; //115200
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(UART5, &USART_InitStructure);
USART_Cmd(UART5, ENABLE);
发送 代码
USART_SendData(UART5 , shuju);
while( USART_GetFlagStatus(UART5, USART_FLAG_TC) == RESET );
|
STM32串口通讯的问题 | 在对USART初始化后,每次上电发送的第一个数据总没有,后续的数据全部正常,是否还需要对哪个标志位进行配置呢?
初始化代码
/* USART5 mode config */
USART_InitStructure.USART_BaudRate = 9600; //115200
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(UART5, &USART_InitStructure);
USART_Cmd(UART5, ENABLE);
发送 代码
USART_SendData(UART5 , shuju);
while( USART_GetFlagStatus(UART5, USART_FLAG_TC) == RESET );
| 在对USART初始化后,每次上电发送的第一个数据总不能用串口工具接收到,后续的数据全部正常,是否还需要对哪个标志位进行配置呢?
初始化代码
/* USART5 mode config */
USART_InitStructure.USART_BaudRate = 9600; //115200
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(UART5, &USART_InitStructure);
USART_Cmd(UART5, ENABLE);
发送 代码
USART_SendData(UART5 , shuju);
while( USART_GetFlagStatus(UART5, USART_FLAG_TC) == RESET );
|
回复:STM32串口通讯的问题
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, byte);
试试
RE:STM32串口通讯的问题
改成
while( USART_GetFlagStatus(UART5, USART_FLAG_TC) == RESET );
USART_SendData(UART5 , shuju);
就没有问题了。
回复:STM32串口通讯的问题
你把发送 代码改成:
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, byte);
试试
请问 判断TXE和TC 有什么区别呢?
回复:STM32串口通讯的问题