最近在STM32上写了一份串口通信的程序,但下载复位后串口却不能工作,初始化的代码如下:
//发送/接收的GPIO、串口和中断的初始化结构体
GPIO_InitTypeDef GPIO_InitStructureTx;
GPIO_InitTypeDef GPIO_InitStructureRx;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//设置发送和接收引脚
GPIO_InitStructureTx.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructureRx.GPIO_Pin = GPIO_Pin_10;
//发送引脚设置为推挽复用、接收引脚设置为浮空输入
GPIO_InitStructureTx.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructureRx.GPIO_Mode = GPIO_Mode_IN_FLOATING;
//设置引脚工作频率
GPIO_InitStructureRx.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructureTx.GPIO_Speed = GPIO_Speed_50MHz;
//引脚初始化
GPIO_Init(GPIOA, &GPIO_InitStructureTx);
GPIO_Init(GPIOA, &GPIO_InitStructureRx);
//波特率
USART_InitStructure.USART_BaudRate = USART_BaudRate;
//数据长度
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
//停止位
USART_InitStructure.USART_StopBits = USART_StopBits_1;
//校验位
USART_InitStructure.USART_Parity = USART_Parity_No;
//流控制
USART_InitStructure.