- 在工程中增加gpio lib.h和stm32头文件,如下:
#include “stm32f10x.h” // Device header
#include “stm32f10x_gpio.h” 调用lib配置gpio工作方式,先开启时钟,选GPIO,设置GPIO mode,gpio speed,主要看GPIO_InitTypeDef 结构体,芯片不同结构体不同,开始不清楚具体使用可以参考系统自带的example code,my setting如下:
void GPIO_Initmain(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure all unused GPIO port pins in Analog Input mode (floating input
trigger OFF), this will reduce the power consumption and increase the device
immunity against EMI/EMC ***************************************/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_3|GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(
stm32 起步 gpio操作
最新推荐文章于 2023-12-06 11:42:43 发布
这篇博客介绍了如何在STM32项目中初始化GPIO并进行操作。首先,需要包含相应的头文件,然后通过配置GPIO_InitTypeDef结构体来设定GPIO的工作模式、速度。在GPIO_Initmain函数中,开启GPIO时钟并初始化GPIO管脚。接着,博主提供了延迟函数Delay以及在主函数main中演示了GPIO的拉高、拉低操作。通过编译下载,实现了GPIO的正确操作。
摘要由CSDN通过智能技术生成