步骤:
1.时钟使能:GPIO时钟使能,串口时钟使能。
RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
2.端口配置:GPIO引脚配置,复用模式。
GPIO_InitTypeDef GPIO_Struct;
GPIO_Struct.GPIO_Pin=GPIO_Pin_9;
GPIO_Struct.GPIO_Mode=GPIO_Mode_AF;
GPIO_Struct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Struct.GPIO_OType=GPIO_OType_PP;
GPIO_Struct.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_Init(GPIOF,&GPIO_Struct);
GPIO_Struct.GPIO_Pin=GPIO_Pin_10;
GPIO_Struct.GPIO_Mode=GPIO_Mode_AF;
GPIO_Struct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Struct.GPIO_OType=GPIO_OType_PP;
GPIO_Struct.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_Init(GPIOF,&GPIO_Struct);
端口为复用模式。
3.串口配置:串口参数初始化,串口使能,并开启中断。