使用串口实现接收和发送功能
一、前言
本文以串口-USART1为例,初步实现接收和发送功能,使用的是stm32f1板子,基于火哥教学做的自我小结。电脑设备需要安装串口调试助手和USB转串口CH340G的驱动。
二、正文
1.硬件设计:
将 CH340G 的 TXD 引脚与 USART1 的 RX 引脚连接, CH340G 的 RXD 引脚与USART1 的 TX 引脚连接,此处已在开发板上配置好了,我们只需进行编程。
—————————————————————————————————
USART1的引脚重映射是PA9和PA10
2.软件设计:
编写的要点:①提前在头文件中写好需要的宏定义 ②初始化GPIO和USART1编写于一个函数中 ③串口中断优先级配置,包括配置接受中断 ④使能串口 ⑤编写中断函数 ⑥编写发送和接收函数
—————————————————————————————————
①编写头文件“bsp_usart.h”
若想使