Introduction to 8 working modes of GPIO in STM32

Publisher:星尘散落Latest update time:2017-11-03 Source: eefocusKeywords:STM32  GPIO Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Push-pull output: can output high and low levels, connect digital devices; push-pull structure generally means that two transistors are controlled by two complementary signals, and one transistor is always turned on while the other is turned off. The high and low levels are determined by the power supply of the IC.

The push-pull circuit is two transistors or MOSFETs with the same parameters, which exist in the circuit in a push-pull manner. Each is responsible for the waveform amplification task of the positive and negative half cycles. When the circuit is working, only one of the two symmetrical power switch tubes is turned on at a time, so the conduction loss is small and the efficiency is high. The output can both inject current into the load and extract current from the load. The push-pull output stage not only improves the load capacity of the circuit, but also increases the switching speed.

2. Open-drain output: The output terminal is equivalent to the collector of the transistor. A pull-up resistor is required to obtain a high-level state. It is suitable for current-type driving and has a relatively strong ability to absorb current (generally within 20mA). The open-drain circuit has the following characteristics:


1. Use the driving capability of the external circuit to reduce the driving inside the IC. When the MOSFET inside the IC is turned on, the driving current flows from the external VCC through the pull-up resistor, MOSFET to GND. Only a small gate driving current is required inside the IC.


2. Generally speaking, open drain is used to connect devices of different levels and match the levels. Because when the open drain pin is not connected to an external pull-up resistor, it can only output a low level. If you need to have the function of outputting a high level at the same time, you need to connect a pull-up resistor. A good advantage is that by changing the voltage of the pull-up power supply, you can change the transmission level. For example, adding a pull-up resistor can provide TTL/CMOS level output, etc. (The resistance value of the pull-up resistor determines the speed of the logic level conversion. 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 both power consumption and speed.)


3. Open-drain output provides a flexible output mode, but it also has its weakness, which is the delay of the rising edge. Because the rising edge charges the load through an external pull-up passive resistor, when the resistor is small, the delay is small, but the power consumption is large; conversely, 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.


4. Multiple open-drain outputs can be connected to one line. Through a pull-up resistor, without adding any devices, a "logical AND" relationship is formed, that is, "wired AND". It can be simply understood as: when all pins are connected together, an external pull-up resistor is connected. If one pin outputs a logic 0, it is equivalent to being grounded, and the loop connected in parallel with it is "equivalent to being short-circuited by a wire", so the logic level of the external circuit is 0. Only when they are all high levels, the result of AND is a logic 1.


Regarding push-pull output and open-drain output, we can finally summarize them with the simplest diagram: the left side of the diagram is the push-pull output mode, in which the lower PNP transistor is cut off when the comparator outputs a high level, and the upper NPN transistor is turned on, and the output level is VS+; when the comparator outputs a low level, it is just the opposite, the PNP transistor is turned on, the output is connected to the ground, and it is a low level. The right side can be understood as an open-drain output form, which needs to be pulled up.


3. Floating input: Since floating input is generally used for external button input, combined with the input circuit in the figure, I understand that in the floating input state, the level state of IO is uncertain and is completely determined by the external input. If the pin is left floating, the level of the port is uncertain.


4. Pull-up input/pull-down input/analog input: These concepts are easy to understand and can be easily understood from the literal meaning.


5. Multiplexed open-drain output and multiplexed push-pull output: This can be understood as the configuration when the GPIO port is used as a second function (that is, not used as a general IO port)


6. Summary of the selection of IO mode in STM32

       1. Floating input GPIO_IN_FLOATING ——Floating input, can be used for KEY recognition, RX1

       2. GPIO_IPU with pull-up input——IO internal pull-up resistor input

       3. GPIO_IPD with pull-down input——IO internal pull-down resistor input

       4. Analog input GPIO_AIN - Use ADC analog input or save power in low power consumption

       5. Open-drain output GPIO_OUT_OD - IO output 0 is connected to GND, IO output 1 is left floating, and an external pull-up resistor is required to achieve a high output level. When the output is 1, the state of the IO port is pulled high by the pull-up resistor, but because it is an open-drain output mode, the IO port can also be changed to a low level or unchanged by an external circuit. The IO input level change can be read to realize the IO bidirectional function of C51

       6. Push-pull output GPIO_OUT_PP - IO output 0 - connected to GND, IO output 1 - connected to VCC, the read input value is unknown

       7. Push-pull output GPIO_AF_PP of multiplexed function - on-chip external function (SCL, SDA of I2C)

       8. Open-drain output GPIO_AF_OD of multiplexed function——on-chip external function (TX1, MOSI, MISO.SCK.SS)

7. STM32 setting example:

       1. Use open-drain output _OUT_OD to simulate I2C, connect a pull-up resistor, and it can correctly output 0 and 1; when reading the value, first GPIO_SetBits(GPIOB, GPIO_Pin_0); pull high, and then you can read the IO value; use GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0);

       2. If there is no pull-up resistor, the IO is high level by default. If you need to read the value of IO, you can use pull-up input_IPU, floating input_IN_FLOATING and open-drain output_OUT_OD;


8. There are usually 5 ways to use a pin function, and their configuration methods are as follows:

      1. As a normal GPIO input: configure the pin as a floating input, an input with a weak pull-up, or an input with a weak pull-down as required, and do not enable all the multiplexed function modules corresponding to the pin.

      2. As a normal GPIO output: configure the pin as push-pull output or open-drain output as required, and do not enable all the multiplexed function modules corresponding to the pin.

      3. As a normal analog input: configure the pin to analog input mode, and do not enable all the multiplexed function modules corresponding to the pin.

      4. As the input of built-in peripherals: configure the pin as a floating input, an input with a weak pull-up, or an input with a weak pull-down as required, and enable a multiplexed function module corresponding to the pin.

      5. As the output of built-in peripherals: configure the pin as multiplexed push-pull output or multiplexed open-drain output as needed, and enable all multiplexed function modules corresponding to the pin.

      Note that if there are multiple multiplexing function modules corresponding to the same pin, only one of them can be enabled, and the other modules remain disabled. For example, if you want to use the USART3 function of pins 47 and 48 of STM32F103VBT6, you need to configure pin 47 as multiplexed push-pull output or multiplexed open-drain output, configure pin 48 as a certain input mode, enable USART3 and keep I2C2 disabled. If you want to use pin 47 of STM32F103VBT6 as TIM2_CH3, you need to remap TIM2 and then configure the corresponding pins in the multiplexing function mode.


Keywords:STM32  GPIO Reference address:Introduction to 8 working modes of GPIO in STM32

Previous article:Three modes of TIM output comparison in STM32
Next article:Detailed explanation of STM32F103 series microcontroller timer

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号