STM32F4 input/output (GPIO) mode understanding

Source: Internet
Author: User

There are several types of stm32 Gpio configuration modes, including: 1. analog input; 2. floating air input; 3. pull-up input; 4. Drop- down input; 5. open-drain output; 6. push-pull output; 7. re-use open-drain output; 8. multiplexing push-pull output is the schematic diagram of the GPIO structure: 1. Analog inputfrom what we can see, I think the most important thing about analog input is that he doesn't go through the input data register, so we can't get the value of the analog input by reading the input data register, which I think is very well understood, because the input data register is not 0 or 1, The analog input signal does not meet this requirement, so it is not possible to put the input data register naturally. The input mode allows us to obtain an external analog signal. 2. Floating Air inputthe input state, my understanding is that its input is entirely outside the decision, I think in data communication should be able to use this mode. Should be in the data communication, our intuitive understanding is that both ends of the line connected to the sending side and receive the break, they need to accurately obtain the other side of the signal level, do not need external intervention. So I think this situation is suitable for floating-space input. For example, we are familiar with the i²c communication. 3 Pull-up inputThe pull-up input is the use of a pull-up resistor on the input circuit. The advantage of this model is that when we do not enter anything, because of the internal pull-up resistor, our processor will feel that we have entered a high level, which avoids the uncertainty of the input. This is useful in situations where the input level is required to be both high and low levels. 4 drop-down inputsimilar to the pull-up input, but when the drop-down is not entered externally, our processor will feel that we have entered a low level. 5 open-Drain outputopen-Drain output, the output is equivalent to the transistor collector, so suitable for use with current-driven applications. To get a high level, pull-up resistors are required. 6 push-Pull outputPush -Pull output uses a push-pull circuit, combined with the characteristics of the push-pull circuit, it is composed of two MOSFETs, one conduction, and the other up to two MOSFETs connected to the high and low levels, so which one will output the corresponding level. The push-pull circuit is fast and the output is strong, and the direct output is high level or low level. 7 multiplexing Open-drain and multiplexed push-pull We know it's just a re-use of Gpio. So that the ordinary gpio has other functions.

push-Pull output: can output high, low level, connect digital devices; Push-pull structure is generally referred to as two transistors by two complementary signal control, always in one transistor on the time of the other cutoff. High and low levels are determined by the IC's power supply.

the push-pull circuit is a two-parameter transistor or MOSFET, a push-pull method exists in the circuit , each is responsible for positive and negative half-week waveform amplification Task , when the circuit is operating, two symmetrical power switch tubes have only one conduction at a time, so the conduction loss is small . , high efficiency. The output can either sink current to the load or pump current from the load . The push-pull output stage increases the load capacity of the circuit and increases the switching speed.

Detailed Understanding:



, the output stage of the push-pull amplifier has two "arms" (two sets of amplification elements), while the current of one "arm" increases, the current of the other "arm" decreases, and the state of the two shifts. For the load, it seems to be an "arm" in the push, an "arm" in the pull, together to complete the current output task. When the output high level, that is, the lower load gate input high level, the output of the current will be subordinate door from the power supply by VT3 pull out. In this way, the output high and low level, VT3 and VT5 Road will be alternating work, thereby reducing the power consumption, improve the capacity of each tube. And because no matter where to go, the resistance of the tube is very small, so that the RC constant is very small, the transition speed is very fast. Therefore, the push-pull output stage improves the load capacity of the circuit and improves the switching speed.

open-Drain output: the output is equivalent to a transistor collector. A pull-up resistor is required to obtain a high level state. Suitable for the current-type drive, its ability to absorb current is relatively strong (generally 20ma or less).

The circuit of the open-drain form has several features:

1. Use the external circuit drive capability to reduce the internal drive of the IC. When the IC internal MOSFET is on, the drive current is from the external VCC through R pull-up, MOSFET to GND. Only a very lower gate drive current is required inside the IC.

2.In General, the open-drain is used to connect different levels of the device, matching the level , because the open-drain pin is not connected to the external pull-up resistor , can only output low level , if need to have output high level function, then need to pull up the resistor, a good advantage is that by changing the voltage of the pull-up power supply, you can change the transmission level. For example , with the pull-up resistor you can provide ttl/cmos level output and so on. ( The resistance of the pull-up resistor determines the speed at which the logic level transitions along. The higher the resistance, the lower the power consumption, the less Therefore, the choice of load resistance should take into account both power consumption and speed .

open-drain provides flexible output, but also has its weaknesses, which is the delay of the rising edge. Because the rising edge is the load charging through the external pull-up passive resistor, so when the resistance choice hour delay is small, but the power consumption is large, and the delay large power consumption is small. Therefore, if the delay is required, it is recommended to use a falling edge output.

4. You can connect multiple open-drain pinsto a single line. A pull-up resistor creates a " and Logic " relationship without adding any devices . This is also an i²c,SMBus and other bus to determine the principle of bus occupancy status. Add: What is "line with"? :

at a junction.(Line)on,connecting a pull-up resistor to the power supplyVCCorVDDand theNaNPNorNMOSCollector of TransistorsCor drain poleD,The emission poles of these transistorsEor source PoleSare on the ground.,as long as there is a transistor saturated,the knot.(Line)is pulled to the ground level..because the base-injected current of these transistors(NPN)or gate plus high level(NMOS),The transistor will saturate .,so these bases or the gate to this junction(Line)the relationship is or is notNORLogic.If this node is followed by an inverting device.,is orORLogic.

In fact, it can be simply understood as: in all pins together, an external pull-up resistor, if there is a pin output logic 0, the equivalent of grounding, the circuit in parallel with it "equivalent to a wire short circuit", so the logic level of the external circuit is 0, only the high power, and the result is logic 1.

With regard to push-pull output and open-drain output, a simple graph is used to summarize:


The left side of the diagram is the push-pull output mode, where the comparator output is high, the following PNP transistor cutoff, and the above NPN transistor conduction, output level vs+; When the comparator output is low, the reverse is true, the PNP transistor is on, the output and the ground are connected to the low level. The right side can be understood as the open-drain output form, need to pull up.


Float input: for floating empty input, has not found a very authoritative explanation, had to understand from the

Since the float input is generally used for external key input, combined with the input circuit on the graph, I understand that the level state of the IO is indeterminate in the floating input state, which is determined entirely by the external input, if the level of reading the port is indeterminate in the case of the pin dangling.

pull-up input/drop-down input/Analog input: These concepts are well understood and can be easily read literally. multiplexed open-drain output, multiplexed push-pull output: can be understood as the configuration when a Gpio port is used as a second function (i.e. not used as a generic IO port) Final Summary of usage: Select IO mode in STM32
(1) Floating empty input _in_floating--float input, can do key identification, RX1
(2) with pull-up input _ipu--io internal pull-up resistor input
(3) with pull-down input _ipd--io internal pull-down resistor input
(4) Analog input _ain--application ADC analog input, or low power consumption to save power
(5) Open-drain output _out_od--io output 0 Gnd,io Output 1, floating, external pull-up resistor is required to achieve high output level. When the output is 1 o'clock, the status 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 be changed from an external circuit to a low level or unchanged. Can read IO input level change, realize C51 io bidirectional function
(6) Push-Pull output _out_pp--io output 0-connection gnd, IO Output 1-VCC, read input value is unknown
(7) Push-pull output of multiplexing function _af_pp--on-chip peripheral function (I²c SCL,SDA)
(8) The open-drain output of multiplexing function _af_od--on-chip peripheral function (Tx1,mosi,miso. SCK. SS)

STM32 Set instance:

(1) Analog i²c using open-drain output _out_od, connect the pull-up resistor, can correctly output 0 and 1, read the value first gpio_setbits (GPIOB, gpio_pin_0), pull up, and then can read the value of IO; use Gpio_readinputdatabit ( GPIOB,GPIO_PIN_0);

(2) If there is no pull-up resistor, io default is high, you need to read the value of Io, you can use the pull-up input _ipu and float input _in_floating and open-drain output _out_od, there are usually 5 ways to use a pin function, they are configured as follows:
1) as a normal Gpio input: Configure the PIN as required toFloating Air Input、with weak pull-up inputOrwith weak drop-down input, and do not enable all the multiplexed function modules that can correspond to the pin.
2) as normal Gpio output: Configure the PIN as required topush-Pull outputOropen-Drain output, and do not enable all the multiplexed function modules that can correspond to the pin.
3) as a normal analog input: Configure the PIN asAnalog Input mode, and do not enable all the multiplexed function modules that can correspond to the pin.
4) as input to the built-in peripherals: Configure the pin as needed toFloating Air Input、with weak pull-up inputOrwith weak drop-down input, while enabling the pin to correspond to a multiplexed function module.
5) as the output of the built-in peripheral: Configure the PIN as needed tomultiplexed push-Pull outputOrmultiplexed Open-Drain output, while enabling all the multiplexed function modules that the pin corresponds to.

Note If there are multiple multiplexed function modules that correspond to the same pin, only one of them can be enabled, and the other modules remain in a non-enabled state.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

STM32F4 input/output (GPIO) mode understanding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.