STM32 GPIO_ReadInputDataBit 的使用(附详细代码 = 引脚底层配置 + 使用)

文章目录

      • 介绍:
      • 引脚底层配置:
      • 读取引脚电平:
      • 小结


介绍:

  • 函数 GPIO_ReadInputDataBit 读的是 GPIOx_IDR
  • 读的是当 IO 口设置为输入状态时候的 IO 口电平状态值。

引脚底层配置:

  • 输入类型:下拉输入
  • 引脚底层配置代码:
    
    void GPIO_DI_Configration(void)
    {
        GPIO_InitTypeDef  GPIO_InitStructure;
        
        /*使能 APB2 - PD端口时钟*/ 
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);	 
        
        /*引脚配置*/
        GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_8 ;				// 引脚 PD.8 
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;		// 频率为50MHz
    	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;       	// 输入类型(下拉输入)	  
    	GPIO_Init(GPIOD, &GPIO_InitStructure); 
    }
    
    

读取引脚电平:

  • 代码:
    	
    	uint8_t CurrLevel;					//当前电平状态
    	
    	/*读取引脚当前电平状态*/
    	CurrLevel = GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_8 );
    
    

小结

  • 欢迎纠正
  • ☆⌒(*^-゜)v THX!!
  • 码字不易,记得点小心心 ( •̀ ω •́ )✧

你可能感兴趣的:(#,IO引脚,c语言,stm32,gpio,引脚电平)