UART1中断服务函数
作者:互联网
UART1中断
1 extern SemaphoreHandle_t BinarySemaphore; //二值信号量句柄 2 void USART1_IRQHandler(void) //串口 1 中断服务程序 3 { 4 u8 Res; 5 BaseType_t xHigherPriorityTaskWoken; 6 if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) 7 { 8 Res = USART_ReceiveData(USART1); //(USART1->DR); //读取接收到的数据 9 if ((USART_RX_STA & 0x8000) == 0) //接收未完成 10 { 11 if (USART_RX_STA & 0x4000) //接收到了 0x0d 12 { 13 if (Res != 0x0a) 14 USART_RX_STA = 0; //接收错误,重新开始 15 else 16 USART_RX_STA |= 0x8000; //接收完成了 17 } 18 else //还没收到 0X0D 19 { 20 if (Res == 0x0d) 21 USART_RX_STA |= 0x4000; 22 else 23 { 24 USART_RX_BUF[USART_RX_STA & 0X3FFF] = Res; 25 USART_RX_STA++; 26 if (USART_RX_STA > (USART_REC_LEN - 1)) 27 USART_RX_STA = 0; 28 } 29 } 30 } 31 } 32 //释放二值信号量 33 if ((USART_RX_STA & 0x8000) && (BinarySemaphore != NULL)) 34 { 35 //释放二值信号量 36 xSemaphoreGiveFromISR(BinarySemaphore, &xHigherPriorityTaskWoken); 37 (1) 38 portYIELD_FROM_ISR(xHigherPriorityTaskWoken); //如果需要的话进行一次任务切换 39 } 40 }
标签:函数,USART,中断,Res,RX,UART1,接收,USART1,STA 来源: https://www.cnblogs.com/kunshanpipixia/p/14472354.html