STM32串口收发

回调函数,位于usart.c

void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
if(huart->Instance == USART1)
{
HAL_UART_Transmit_DMA(&huart1, my_string, Size);
}
}
中断处理函数,位于 stm32f1xx_it.c

void USART1_IRQHandler(void)
{
/* USER CODE BEGIN USART1_IRQn 0 /


/
USER CODE END USART1_IRQn 0 /
HAL_UART_IRQHandler(&huart1);
/
USER CODE BEGIN USART1_IRQn 1 /
HAL_UARTEx_ReceiveToIdle_DMA(&huart1, my_string, 512);
/
USER CODE END USART1_IRQn 1 */
}