stm32学习记录随笔23.11.3

发布时间 2023-11-03 22:41:07作者: 上够了逼班的老王

RCC外设时钟使能常用函数

//标准库文件 ->stm32f10x_rcc.h

void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState);
//RCC_AHB外设时钟控制
void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
//RCC_APB2外设时钟控制
void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);
//RCC_APB1外设时钟控制

初时GPIO常用函数
//标准库文件 ->stm32f10x.gpio.h

void GPIO_DeInit(GPIO_TypeDef* GPIOx);
//指定GPIOx外设复位
void GPIO_AFIODeInit(void);
//AFIO外设复位
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
//使用结构体的参数初始化GPIO
void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
//使结构体变量赋默认值

//四种读取函数(输入)
uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
//四种写入函数(输出)
void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);//设置高电平输出
void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);//设置低电平输出
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);//写入字节位选择,Bit_SET高电平Bit_RESET清除电平即低电平
void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);

GPIO的输入输出模式
1. 四种输入模式
 GPIO_Mode_IN_FLOATING //浮空输入模式,需外接上拉或下拉电阻否则电平信号不稳定,STM32有直接控制权
 GPIO_Mode_IPU         //上拉输入模式,内部弱上拉电阻,默认高电平信号1,STM32有直接控制权
 GPIO_Mode_IPD         //下拉输入模式,内部弱下拉电阻,默认低电平信号0,STM32有直接控制权
 GPIO_Mode_AIN         //模拟输入模式,断开与STM32的直接链接,片上外设接受信号,STM32无直接控制权
2. 四种输出模式
 GPIO_Mode_Out_OD      //开漏输出模式,有较强的负载能力,默认接地,需要外接上拉电阻拉高外设电平
 GPIO_Mode_Out_PP      //推挽输出模式,有较强的负载能力(约20ma可以点灯)
 GPIO_Mode_AF_OD       //复用开漏输出模式,与片上外设有关,参与设置I2C/SPI等协议
 GPIO_Mode_AF_PP       //复用推挽输出模式,与片上外设有关,参与设置I2C/SPI等协议