问题一:配置GPIO的步骤
现在做一个最简单的GPIO控制LED的 GPIO初始化
(1)初始化结构体
GPIO_InitTypeDef GPIO_InitStructure;
(2)使能相应的时钟(程序最初应该有#define RCC_GPIO_LED GPIOB 或其他组端口)
RCC_APB2PeriphClockCmd(RCC_GPIO_LED , ENABLE);
(3)对GPIO结构体初始化。
GPIO结构体:
typedef struct
{
uint16_t GPIO_Pin; //选择管脚,是你想用到的管脚
GPIOSpeed_TypeDef GPIO_Speed; //选择速度 可选2M 10M 50M
GPIOMode_TypeDef GPIO_Mode; //输入输出的8种模式,这要根据外电路和作用选择
}GPIO_InitTypeDef;
/* LEDs pins configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_LED_ALL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //LED 一般就选推挽输出了
GPIO_Init(GPIO_LED, &GPIO_InitStructure);
问题二: 什么时候用 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;中IPU是指IO口的工作模式是带上拉输入,这个和具体的电路有关,总之如果选择某个IO口作为外部中断的触发信号,就必须配置这个IO口为输入模式,不然无法触发中断
分享到:
相关推荐
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU; GPIO_Init(GPIOE,&GPIO;_InitStructure);} #define MIPI_DATA_OUT() {GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_OD; ...
STM32模拟IIC代码 void I2C_GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Configure I2C1 pins: SCL and SDA */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_...
STM32模拟I2C时序的初始化程序 void I2C_INIT(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = I2C_SCL | I2C_SDA; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_...
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); ...
RCC_APB2PeriphClockCmd(GENERAL_TIM_CH1_GPIO_CLK, ENABLE); GPIO_InitStructure.GPIO_Pin = GENERAL_TIM_CH1_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_...
RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOC, ENABLE ); //使能GPIOB时钟 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD ; //推挽输出 GPIO_InitStructure...
基于STM32F103_STM32F405单片机的4轴步进电机加减速控制工程软件源码,两个版本源码软件,分别为TM32F103和STM32F405单片机设计,可以同时控制4轴步进电机进行加减速;可供学习及设计参考。 int main(void) { u8 i=...
AD5676 DAC芯片STM32驱动程序源码 #include "Ad5676.h" void Ad5676_init(void) { GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB ...
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入 GPIO_Init(GPIOB, &GPIO_InitStructure);// //MP3 DATA 引脚PB7 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//使能PORTA,时钟 ...
STM32F103ZET6单片机RS485接口通信实验软件例程源码 void RS485_Init(u32 bound) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC...
Corrected pin configuration: MX_I2Cx_SMBA_GPIO_PuPdOD replaced with MX_I2Cx_yyy_GPIO_PuPdOD. Corrected usage function name USB Device: Corrected transmitted count for non-control IN endpoints. Updated...
工程是基于STM32F207的ADC_DMA的整体程序 #define ADC1_DR_Address ((u32)0x4001204C) //ADC1数据寄存器地址=ADC1基准地址(0x40012000)+数据寄存器偏移地址(0x4c) GPIO_InitTypeDef GPIO_InitStructure; ADC_...
基于STM32L452的timer flash gpio usart等外设驱动代码,直接添加可用。 串口使用环形缓冲区收发,增加串口方便简洁 P_UART P_UartTbl[ 3 ] = { [ UART_1 ] = { .USARTx = USART1, .UARTx_IRQn = USART1_...
#include "adxl345.h" u16 x_temp[1],y_temp[1],z_temp[1]; //纭欢IIC锛岃櫄鎷烮IC搴旇鏇村悎閫? void iic_for_adxl345_... GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(GPIOB,&GPIO_InitStr
MTK6771平台GPIO口查询表MT6771_GPIO_Formal_Application_Spec_V1.0.xlsm
视频中库函数跑马灯新建出来的-战舰_精英
在STM32里,对千GPIO的配置种类有8种之多: (1) GPIO_Mode_AIN模拟输入 (2) GPIO_Mode_IN_FLOATING浮空输入 (3) GPIO_Mode_IPD下拉输入 (4) GPIO_Mode_IPU 上拉输入 (5) GPIO_Mode_Out_OD开漏输出 (6) GPIO_Mode_Out...
小白加入嵌入式开发的第一步哦!...GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(LED_PORT, &GPIO_InitStructure); GPIO_ResetBits(LED_PO
CS5460电能采集芯片STM32驱动源码+中文技术手册DATASHEET,可供学习设计参考。 void CS5460_init(void) { u32 Data; GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_...
MediaTek_MT2502A_SOC_Data_Sheet GPIO_Table__v1_0.pdf