复用:将GPIO作为内置的外设使用。
初始化复用端口:
1.GPIO时钟使能,和复用的外设时钟使能
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART|RCC_APB2Periph_GPIOA, ENABLE);
2.端口模式配置
复用的内置外设功能引脚,要根据STM32手册里的所要求的配置来对应GPIO的模式
拿串口举例来说:
我们设置TX设置推挽,RX就要设置浮空或上拉
//USART1_TX PA.9 复用推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART1_RX PA.10 浮空输入
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//PA10
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
GPIO_Init(GPIOA, &GPIO_InitStructure);
相关文章









