STM32-GPIO学习

使用STM32 GPIO的三个步骤

1.使用RCC函数初始化时钟

2.使用GPIO_Init函数初始化GPIO

3.使用输出或者输入函数控制GPIO

初始化时钟:

void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState);
void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);

变量1填具体外设,如GPIOA,GPIOB等。

变量2填ENABLE或DISABLE。

初始化GPIO

先定义结构体,赋值结构体,用结构体对对应GPIO进行初始化。

	GPIO_InitTypeDef GPIO_InitStructure;    //定义结构体
	GPIO_InitStructure.GPIO_Mode = ;    //赋值结构体//可以选择八种输入输出模式
	GPIO_InitStructure.GPIO_Pin = ;    //选中引脚,可以用|选中多个引脚
	GPIO_InitStructure.GPIO_Speed =;    //选中输出速度
	GPIO_Init(GPIOX,&GPIO_InitStructure);    //初始化GPIO

控制GPIO

使用一下八个GPIO输入输出函数进行控制,各自对应不同的用法,注意积累。

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);
void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);

        

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值