STM32-GPIO eight input and output modes

GPIO eight input and output modes

Reference: https://blog.csdn.net/baidu_37366055/article/details/80060962
https://www.cnblogs.com/lweleven/p/mcuioout.html

Input mode

  • Input floating GPIO_Mode_IN_FLOATING
  • Input pull up GPIO_Mode_IPU
  • Input dropdown GPIO_Mode_IPD
  • Analog input GPIO_Mode_AIN

Output mode

  • Push-pull output GPIO_Mode_Out_PP
  • Open drain output GPIO_Mode_Out_OD
  • Open drain multiplexing GPIO_Mode_AF_OD
  • Push-pull multiplexing GPIO_Mode_AF_PP

Insert picture description here

1. Enter floating

Floating, as the name suggests, is equivalent to not connecting anything to this port by default, and is in a high impedance state. The biggest feature of floating is the uncertainty of the voltage. It may be 0V, it may be VCC, or it may be a value between the two (most likely).

2. Input pull up

The uncertain signal is clamped to a high level through a resistor. When there is no input or when the input is high, it is high, and when the input is low, it is low.
Insert picture description here

3. Input drop down

The uncertain signal is clamped at a low level through a resistor. When there is no input or when the input is low, it is low, and when the input is high, it is high.
Insert picture description here

4. Analog input

After the signal enters, without the pull-up resistor or the pull-down resistor, the Schmitt trigger is turned off, and the voltage signal is transmitted to the on-chip peripheral module through another line. For example, it is sent to the ADC module, and the voltage signal is collected by the ADC.
Insert picture description here

5. Push-pull output

The so-called push-pull output mode is named according to the working mode of the two MOS tubes controlled by the output. When inputting a high level in this structure, after the reverse, the upper P-MOS is turned on, the lower N-MOS is turned off, and the external output is high; and when the low level is input in this structure, after the reverse, N-MOS tube is turned on, P-MOS is turned off, and low level is output to the outside. When the pin is switched between high and low levels, the two tubes are turned on in turn, the P tube is responsible for sinking current, and the N tube is responsible for sourcing current, so that its load capacity and switching speed are greatly improved compared with ordinary methods. The low level of the push-pull output is 0V, and the high level is 3.3V.
Insert picture description here

6. Open drain output

In the open-drain output mode, the upper P-MOS tube does not work at all. If we control the output to 0, low level, the P-MOS tube is turned off, the N-MOS tube is turned on, and the output is grounded, if the control output is 1 (it cannot directly output high level), the P-MOS tube Both the N-MOS and N-MOS transistors are turned off, so the pin neither outputs a high level nor a low level, and is in a high impedance state. During normal use, a pull-up resistor must be connected externally, and the pull-up resistor provides a high level. This high-level voltage is the voltage connected to the external pull-up resistor.

Tips: Push-pull output mode is generally used in situations where the output level is 0 and 3.3 volts and high-speed switching is required. In the application of STM32, we are accustomed to using push-pull output mode except where open-drain mode must be used. Open-drain output is generally used in I2C, SMBUS communication and other bus circuits that require line and function 1 . In addition, it is also used in situations where the level does not match. If you need to output a high level of 5 volts, you can connect a pull-up resistor externally, the pull-up power is 5 volts, and set the GPIO to open drain mode , When the output is in the high impedance state, a 5 volt level is output from the pull-up resistor and the power supply.

7. Open drain multiplexing

It can be understood as the configuration when the GPIO port is used as the second function (that is, it is not used as a general-purpose IO port), and the port must be configured as a multiplex function output mode.

8. Push-pull multiplexing

Same as open drain multiplexing.


  1. If there are many open-drain mode pins connected together, only when all pins output high-impedance state, the pull-up resistor will provide high level. This high-level voltage is the power supply connected to the external pull-up resistor The voltage. If one of the pins is low, the line is equivalent to a short circuit to ground, making the entire line low. ↩︎

Guess you like

Origin blog.csdn.net/lblmlms/article/details/109244694