复用:将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);

 

相关文章:

  • 2021-06-04
  • 2022-01-06
  • 2022-02-14
  • 2021-08-08
  • 2022-01-07
  • 2021-05-23
  • 2021-10-30
  • 2021-10-17
猜你喜欢
  • 2022-12-23
  • 2022-01-08
  • 2021-12-19
  • 2021-04-21
  • 2022-01-31
  • 2022-12-23
  • 2021-11-28
相关资源
相似解决方案