摘自于rtthread 中断串口接收 代码


 1 static void uart_isr(struct rt_serial_device *serial) 
 2 {
 3     struct stm32_uart *uart = (struct stm32_uart *) serial->parent.user_data;
 4 
 5     RT_ASSERT(uart != RT_NULL);
 6     //isr_index++;
 7     if(USART_GetITStatus(uart->uart_device, USART_IT_RXNE) != RESET)  8  {  9         
10         if(USART_GetFlagStatus(uart->uart_device, USART_FLAG_PE) == RESET) 11  { 12             
13  rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND); 14  } 15         /* clear interrupt */
16         USART_ClearITPendingBit(uart->uart_device, USART_IT_RXNE); 17  } 18 #ifdef RT_SERIAL_USING_DMA    
19     if(USART_GetITStatus(uart->uart_device, USART_IT_IDLE) != RESET)
20     {
21         dma_uart_rx_idle_isr(serial);
22     }
23 #endif /* RT_SERIAL_USING_DMA */     
24     if (USART_GetITStatus(uart->uart_device, USART_IT_TC) != RESET)
25     {
26         /* clear interrupt */
27         if(serial->parent.open_flag & RT_DEVICE_FLAG_INT_TX)
28         {
29             rt_hw_serial_isr(serial, RT_SERIAL_EVENT_TX_DONE);
30         }
31         USART_ITConfig(uart->uart_device, USART_IT_TC, DISABLE);
32         USART_ClearITPendingBit(uart->uart_device, USART_IT_TC);
33     }
34     if (USART_GetFlagStatus(uart->uart_device, USART_FLAG_ORE) == SET) // overrun error 35  { 36         USART_ReceiveData(uart->uart_device); 37  } 38 }

加上这篇文章(https://shequ.stmicroelectronics.cn/forum.php?mod=viewthread&tid=613968),注意串口数据接收


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM