STM32F103串口不能发送,死循环

2019-07-16 09:24发布

void USART3_Send_Byte(unsigned char ucSend_Data)
{
          USART_SendData(USART3, ucSend_Data);
          while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
}

一直在 while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);死循环,不能进串口的中断。






中断这样配置对不?
/************************************************************ 函数名: NVIC_Config** 功能描述: 中断分组及优先级配置** 输入参数: 无** 输出参数: 无***********************************************************/void NVIC_Config(void){  NVIC_InitTypeDef NVIC_InitStructure;        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  /*定时器3中断 */  NVIC_InitStructure.NVIC_IRQChannel = tiM1_CC_IRQn;  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  NVIC_Init(&NVIC_InitStructure);                NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  NVIC_Init(&NVIC_InitStructure);                NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  NVIC_Init(&NVIC_InitStructure);                NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  NVIC_Init(&NVIC_InitStructure);         NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;   //通道设置为串口1中断(故后面应选择在“void USART1_IRQHandler(void)”开中断)     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;    //中断占先等级0    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;          //中断响应优先级0    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  //打开中断    NVIC_Init(&NVIC_InitStructure);}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
2条回答
z00
1楼-- · 2019-07-16 14:27
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, c);
先判断然后再发送
woodmice
2楼-- · 2019-07-16 19:43
数据被正确接收没?
先检查下串口配置是否正确,端口方向,驱动方式,时钟开关,定时器开关;

一周热门 更多>