//DMA接收定义为循环模式,只能接受定长数据
//串口DMA中断调用的回调函数和串口接收中断是同一个
uint8_t rxch[5];
uint8_t trch[]="transmit dma:\r\n";
int main(void)
{
HAL_UART_Transmit_DMA(&huart1,trch,15);
HAL_UART_Receive_DMA(&huart1,rxch,5);
while (1)
{
}
}
//DMA接收完成回调函数和这是同一个
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart->Instance==USART1)
{
printf("%s\r\n",rxch);
HAL_UART_Transmit_DMA(&huart1,rxch,5);
}
}
//DMA传输完成回调函数和这是同一个
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
uint8_t tx_str[] = "Data Transfer completed\r\n";
HAL_UART_Transmit(&huart1,tx_str,sizeof(tx_str),200);
}
来源:CSDN
作者:sea1216
链接:https://blog.csdn.net/sea1216/article/details/104270331