--- title: 串口DMA不定长接收 updated: 2022-01-11 01:27:13Z created: 2022-01-08 13:18:08Z tags: - mcu - 串口 - 代码块 --- 串口不定长接收利用的是串口接收中的空闲中断 处理空闲中断 ```c /** * @brief This function handles USART1 global interrupt. */ void USART1_IRQHandler(void) { /* USER CODE BEGIN USART1_IRQn 0 */ uint32_t flag,tmp; flag = __HAL_UART_GET_FLAG(&huart1,UART_FLAG_IDLE); if (flag != RESET) { __HAL_UART_CLEAR_IDLEFLAG(&huart1); tmp = huart1.Instance->SR; tmp = huart1.Instance->DR; HAL_UART_DMAStop(&huart1); tmp = hdma_usart1_rx.Instance->CNDTR; rxlen = 200 - tmp; isrxend = 1; } /* USER CODE END USART1_IRQn 0 */ HAL_UART_IRQHandler(&huart1); /* USER CODE BEGIN USART1_IRQn 1 */ /* USER CODE END USART1_IRQn 1 */ } ``` #串口 #mcu #代码块