stm32自学阶段性总结1(端口复用与重映射)

又是周末加月末,是时候来总结一下了

一、端口复用(以PA9复用为串口1为例)

相关配置过程:
1 :首先使能GPIO端口的时钟使能:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

2:所需要的外设时钟使能 例如:RCC_APB2PeriphClockCmd_USART()

3:端口的模式设置 GPIO_init();
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);//初始化端口,注意将端口MODE设置为复用模式.

二 : 端口重映射(串口一为例)

相关配置:
1 使能GPIO时钟:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
2 使能外设即串口1的时钟:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
3开启重映射时钟(重映射必须开启重映射时钟):
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
4开启重映射:
GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE);
注意:重映射需要看是完全重映射还是部分重映射

你可能感兴趣的:(stm32,阶段性总结)