图像处理大大大大大牛啊 2021-11-03 14:33 采纳率: 0%
浏览 378
已结题

stm32f405 串口同时接收发送 接收数据导致卡死

接收到数据的时候会被卡死


void uart3_init(u32 bound)
{       
  GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;
    NVIC_InitTypeDef NVIC_InitStructure;
    
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);//使能USART1时钟
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
    
    GPIO_PinAFConfig(GPIOC,GPIO_PinSource10,GPIO_AF_USART3);
    GPIO_PinAFConfig(GPIOC,GPIO_PinSource11,GPIO_AF_USART3);
    
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; //GPIOC10与GPIOC11
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;    //速度50MHz
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
    GPIO_Init(GPIOC,&GPIO_InitStructure); //初始化PA9,PA10
    
    
  //USART Initialization Settings 初始化设置
    USART_InitStructure.USART_BaudRate = bound; //Port rate //串口波特率
    USART_InitStructure.USART_WordLength = USART_WordLength_8b; //The word length is 8 bit data format //字长为8位数据格式
    USART_InitStructure.USART_StopBits = USART_StopBits_1; //A stop bit //一个停止
    USART_InitStructure.USART_Parity = USART_Parity_No; //Prosaic parity bits //无奇偶校验位
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //No hardware data flow control //无硬件数据流控制
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;    //Sending and receiving mode //收发模式
  USART_Init(USART3, &USART_InitStructure);      //Initialize serial port 3 //初始化串口3
    
  USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); //Open the serial port to accept interrupts //开启串口接受中断
  USART_Cmd(USART3, ENABLE);                     //Enable serial port 3 //使能串口3 

  //UsartNVIC configuration //UsartNVIC配置
  NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
    //Preempt priority //抢占优先级
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;
    //Preempt priority //抢占优先级
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;        
    //Enable the IRQ channel //IRQ通道使能    
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;    
  //Initialize the VIC register with the specified parameters 
    //根据指定的参数初始化VIC寄存器        
    NVIC_Init(&NVIC_InitStructure);
}
int USART3_IRQHandler(void)
{    
    u8 Usart_Receive;
    if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) //Check if data is received //判断是否接收到数据
    {
        Usart_Receive = USART_ReceiveData(USART3);//Read the data //读取数据
        
    } 
return 0;    
}
void usart3_send(u8 data)
{
    
    while((USART3->SR&0x40)==0);    
    USART3->DR = data;
}
  • 写回答

3条回答 默认 最新

  • baidu_30233079 2021-11-03 14:54
    关注

    51行后面加上清除中断标识就好了
    现在是因为来了一个数据后产生接收中断,但是你没有清中断标志,退出中断后马上又进入中断了,相当于死循环了。

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 11月3日
  • 赞助了问题酬金 11月3日
  • 赞助了问题酬金 11月3日
  • 创建了问题 11月3日

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统