1.STM32CubeMX 配置串口
2.空闲中断接受数据
1.配置接收空闲中断
HAL_UARTEx_ReceiveToIdle_IT(&huart1, rx_buffer,BUFFER_SIZE); //开启空闲中断接收
2.重写空闲中断回调函数,取走数据
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
if(huart == &huart1)
{
lwQueWriteString(&QueRx1, rx_buffer, Size);//数据填入 FIFO
HAL_UARTEx_ReceiveToIdle_IT(&huart1, rx_buffer,BUFFER_SIZE); //准备下次空闲中断
}
}
3.数据的发送
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size, uint32_t Timeout); //阻塞发送
HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size); //中断发送
HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size); //DMA发送