STM32串口通讯中断接收

串口的设置

串口的时序和工作原理就不写了,主要写如何应用
串口的设置除了GPIO外,需要设置的参数有波特率、数据位、停止位,校验方式;
GPIO输出配置AF_PP复用推挽输出
GPIO出入配置IN_FLAOTING浮空输入
USART的配置为115200的波特率,8位数据长度,1位停止位,无校验,无硬件流控制

GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;

/* config USART1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);//打开GPIO和USART1时钟

/* USART1 GPIO config */
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
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);    
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING

你可能感兴趣的:(STM32,STM32,串口中断)