The difference between the eight working modes of STM32GPIO

In Cortex-M3, there are 8 types of GPIO configuration:

(1) GPIO_Mode_AIN analog input 
(2) GPIO_Mode_IN_FLOATING floating input
(3) GPIO_Mode_IPD pull-down input 
(4) GPIO_Mode_IPU pull-up input 
(5) GPIO_Mode_Out_OD open-drain output
(6) GPIO_Mode_Out_PP push-pull output
(7) GPIO_Mode_AF_OD multiplexed open-drain output 
( 8) Basic structure of GPIO_Mode_AF_PP multiplexing push-pull output I /

O port bit In the amplification task, when the circuit is working, only one of the two symmetrical power switches is turned on at a time, so the conduction loss is small and the efficiency is high. The output can either sink current into the load or draw current from the load. The push-pull output stage not only increases the load capacity of the circuit, but also increases the switching speed. 2. The output terminal of the open-drain output is equivalent to the collector of the triode. To get a high-level state, a pull-up resistor is required. It is suitable for current-type driving, and its ability to absorb current is relatively strong (generally within 20ma).


    


     

The open-drain circuit has the following characteristics
    : a. Use the drive capability of the external circuit to reduce the drive inside the IC . When the IC 's internal MOSFET is turned on, the drive current flows from the external VCC through R pull-up  , MOSFET to GND . Only a very low gate drive voltage is required inside the IC .    b. Open-drain is used to connect devices of different levels and to match the level, because when the open-drain pin is not connected to an external pull-up resistor, it can only output a low level. If it is necessary to have a high-level output at the same time To function, you need to connect a pull-up resistor. A good advantage is that the transmission level can be changed by changing the voltage of the pull-up power supply . For example, adding a pull-up resistor can provide TTL/CMOS level output and so on. ( The resistance value of the pull-up resistor determines the speed of the edge of the logic level transition. The larger the resistance value, the lower the speed and the lower the power consumption, so the selection of the load resistor should take into account power consumption and speed. )     c. Multiple Open-drain output Pin, connected to a line. With a pull-up resistor, an "AND logic" relationship is formed without adding any devices. This is also the principle of I2C, SMBus and other buses to judge the bus occupancy status .


   Weakness: Brings the delay of the rising edge. Because the rising edge charges the load through an external pull-up passive resistor, when the resistor is selected small, the delay is small, but the power consumption is large; otherwise, the delay is large and the power consumption is small. Therefore, if there is a requirement for delay, it is recommended to use falling edge output.

3. The multiplexed open-drain output and the multiplexed push-pull output
   are understood as the configuration when the GPIO port is used as the second function.

4.
    
  The floating input is generally used for external key input because the floating input The level state of the port is indeterminate and is completely determined by the external input. If the pin is left floating, the level of reading the port is indeterminate.


5. Pull-up input mode


        The difference is that when there is no input signal, the default input is high level (because there is a weak pull-up). The pull-up resistor is to ensure that the level of the input terminal is high when there is no signal input, and there is also a pull-down resistor to ensure that the level of the input terminal is low when there is no signal input.


6、下拉输入模式
      区别在于没有输入信号的时候默认输入低电平(因为有弱下拉)

7、模拟输入
      输入模拟信号


在STM32中常用IO模式
(1) 浮空输入_IN_FLOATING ——浮空输入,可以做KEY识别,RX1
(2)带上拉输入_IPU——IO内部上拉电阻输入
(3)带下拉输入_IPD—— IO内部下拉电阻输入
(4) 模拟输入_AIN ——应用ADC模拟输入,或者低功耗下省电
(5)开漏输出_OUT_OD ——IO输出0接GND,IO输出1,悬空,需要外接上拉电阻,才能实现输出高电平。当输出为1时,IO口的状态由上拉电阻拉高电平,但由于是开漏输出模式,这样IO口也就可以由外部电路改变为低电平或不变。可以读IO输入电平变化,实现C51的IO双向功能
(6)推挽输出_OUT_PP ——IO输出0-接GND, IO输出1 -接VCC,读输入值是未知的
(7)复用功能的推挽输出_AF_PP ——片内外设功能(TX1,I2C的SCL,SDA)
(8)复用功能的开漏输出_AF_OD——片内外设功能(MOSI,MISO.SCK.SS)

通常有5种方式使用某个引脚功能,它们的配置方式如下:
1)作为普通GPIO输入:根据需要配置该引脚为浮空输入带弱上拉输入带弱下拉输入,同时不要使能该引脚对应的所有复用功能模块。
2)作为普通GPIO输出:根据需要配置该引脚为推挽输出开漏输出,同时不要使能该引脚对应的所有复用功能模块。

3)作为普通模拟输入:配置该引脚为模拟输入模式,同时不要使能该引脚对应的所有复用功能模块。

4)作为内置外设的输入:根据需要配置该引脚为浮空输入带弱上拉输入带弱下拉输入,同时使能该引脚对应的某个复用功能模块。
5)作为内置外设的输出:根据需要配置该引脚为复用推挽输出复用开漏输出,同时使能该引脚对应的所有复用功能模块。

如果有多个复用功能模块对应同一个引脚,只能使能其中之一,其它模块保持非使能状态。

STM32设置实例:
       1、模拟I2C使用开漏输出_OUT_OD,接上拉电阻,能够正确输出0和1;读值时先GPIO_SetBits(GPIOB, GPIO_Pin_0);拉高,然后可以读IO的值;使用GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0);
       2、如果是无上拉电阻,IO默认是高电平;需要读取IO的值,可以使用带上拉输入_IPU和浮空输入_IN_FLOATING和开漏输出_OUT_OD;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324844305&siteId=291194637