一、 串口的基本知识
串口的基本知识,可以参考如下文章:
a.串口基础知识文章1
b.串口基础知识文章2
二、STM32配置USART
下面是配置USART过程的思维导图,如下:
下面是各个过程的具体实现过程,并带有注释。
(1)USART对应GPIO配置
具体代码如下:
GPIO_InitTypeDef GPIO_InitStructure;//定义GPIO结构体
/*开启时钟*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
//UART发送端PA9引脚初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//设置为复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure)