STM32F103 UART中断接收 DMA发送

本文介绍了如何在STM32F103上配置USART3,利用DMA实现串口接收中断和发送功能。首先在`stm32f1xx_hal_conf.h`中启用DMA模块并引入相关文件,接着在`main.c`中声明变量和初始化USART,然后在`stm32f1xx_hal_msp.c`中完成外设连接,最后在`stm32f1xx_it.c`中设置中断处理函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以USART3为例,

(1)首先在【stm32f1xx_hal_conf.h】中使能DMA模块,工程增加stm32f1xx_hal_dma.c。

(2)main.c中头部增加以下声明

UART_HandleTypeDef huart3;
DMA_HandleTypeDef hdma1_uart3;

(3)main.c中增加USART的初始化

/* USART3 init function */
static void MX_USART3_UART_Init(void)
{
	huart3.Instance = USART3;
	huart3.Init.BaudRate = 115200;
	huart3.Init.WordLength = UART_WORDLENGTH_8B;
	huart3.Init.StopBits = UART_STOPBITS_1;
	huart3.Init.Parity = UART_PARITY_NONE;
	huart3.Init.Mode = UART_MODE_TX_RX;
	huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
	huart3.Init.OverSampling = UART_OVERSAMPLING_16;
	if (HAL_UART_Init(&huart3) != HAL_OK)
	{
		Error_Handler();
	}
}

(4)stm32f1xx_hal_msp.c增加

extern  UART_HandleTypeDef huart3;
extern DMA_HandleTypeDef hdma1_uart3;

......................

void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{

	GPIO_InitTypeDef GPIO_InitStruct;
	
	if (huart->Instanc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值