STM32103 的uart5 不知道为什么会死在while (USART_GetFlagStatus(UART5,USART_FLAG_TC) ==RESET);//轮询直到发送数据完毕
在这条语句死循环了 代码如下
void USART5_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* config UART5 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD, ENABLE);
/* UART5 GPIO config */
/* Configure UART5 Tx (PC.12) as alternate func
tion push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure UART5 Rx (PD.02) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* UART5 mode config */
USART_InitStructure.USART_BaudRate = 9600;
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);
void USART_SendDatapoll(uint16_t Data)
{
//Delayms(1);
USART_SendData(UART5, Data);
while (USART_GetFlagStatus(UART5,USART_FLAG_TC) ==RESET);//轮询直到发送数据完毕
//Delayms(1);
}
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
USART_ITConfig(UART5, USART_IT_TC, DISABLE);
USART_Cmd(UART5, ENABLE);
//USART_ClearFlag(UART5, USART_FLAG_TC); // 清标志
}
一周热门 更多>