微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > ARM技术讨论 > STM32F103串口不能发送,死循环

STM32F103串口不能发送,死循环

时间:10-02 整理:3721RD 点击:
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);}

while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, c);
先判断然后再发送

数据被正确接收没?
先检查下串口配置是否正确,端口方向,驱动方式,时钟开关,定时器开关;

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top