1 volatile uint8_t RxBuffer; 2 void StartTask04(void const * argument) 3 { 4 /* USER CODE BEGIN StartTask04 */ 5 uint8_t len; 6 osEvent evt; 7 HAL_UART_Receive_IT(&huart1,&RxBuffer,1); 8 __HAL_UART_ENABLE_IT(&huart1,UART_IT_RXNE);//开启接收中断 9 __HAL_UART_CLEAR_IDLEFLAG(&huart1); 10 11 /* Infinite loop */ 12 for(;;) 13 { 14 osDelay(1); 15 len = osSemaphoreGetCount(UartQueueHandle); 16 while(len--){ 17 evt = osMessageGet(UartQueueHandle,0); 18 printf("%c",(char *)evt.value.p); 19 } 20 21 } 22 /* USER CODE END StartTask04 */ 23 }
1 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) 2 { 3 __HAL_UART_CLEAR_FLAG(&huart1,UART_FLAG_RXNE); 4 HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin); 5 //将数据放入消息队列 6 xQueueSendFromISR(UartQueueHandle,&RxBuffer,NULL); 7 HAL_UART_Receive_IT(&huart1,&RxBuffer,1); 8 }
标签:__,UartQueueHandle,HAL,FreeRTOS,UART,huart1,串口,RxBuffer,接收数据 From: https://www.cnblogs.com/observer01/p/18163019