8 working modes of GPIO in STM32!

Source: Internet
Author: User

One, push-pull output: Can output high, low level, connect digital devices; push-pull structure generally refers to two transistors are controlled by two complementary signals, always in one transistor on the time of the other cutoff. The high and low levels are determined by the IC's power supply.

Push-Pull circuit is two parameters of the same transistor or MOSFET, to push-pull mode exists in the circuit, each responsible for positive and negative half-cycle of the waveform amplification task, the circuit work, two symmetrical power switch tube 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.

Second, open-drain output: The output is equivalent to the transistor collector, to get a high-level state requires a pull-up resistor. 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, the use of external circuit drive capability, reduce the internal drive IC. When the IC internal MOSFET is on, the drive current flows from the external VCC through the pull-up resistor, MOSFET to GND. Only a small gate drive current is required inside the IC.

2, generally, the open-drain is used to connect different levels of the device, matching the level with, because the open-drain pin is not connected to the external pull-up resistor, can only output low level, if you need to have the function of high output level, it is necessary to connect the pull-up resistor, a good thing is to change the power supply voltage, For example, with the pull-up resistor you can provide Ttl/cmos level output and so on. (The resistance value of the pull-up resistor determines the speed of the logic level conversion.) The higher the resistance, the lower the power consumption, so the choice of load resistance should take into account both power consumption and speed. )

3, open-drain output provides a flexible output mode, but also has its weaknesses, is to bring the rising edge of the delay. 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, multiple open-drain outputs can be connected to a line. With a pull-up resistor, the "and logic" relationship, i.e. "line and", is formed without adding any devices. 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, parallel with the circuit "equivalent to a short circuit", so the logic level of the external circuit is 0, only the high power, and the result is logic 1.

on the push-pull output and open-drain output, and finally with a simple graph to summarize: the left side of the graph is the push-pull output mode, wherein the comparator output high power at the time below the PNP transistor cutoff, and the above NPN transistor conduction, output level vs+; When the comparator output is low, the opposite is true, PnP transistor conduction, output and ground connected, low level. The right side can be understood as the open-drain output form, need to pull up.


Three, the float input: for the float input, has not found a very authoritative explanation, had to understand from the following diagram

   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. Iv. pull-up input/drop-down input/analog input: These concepts are well understood and can be read literally and easily. Five, multiplexing open-drain output, multiplexing push-pull output: Can be understood as the configuration of the Gpio port as a second function (that is, not used as a general-purpose IO Port) vi. Summary of the use of IO mode in STM32
   1, floating empty input gpio_in_floating--float input, you can do key identification, RX1
   2, with pull-up input gpio_ipu--io internal pull-up resistor input
   3, with pull-down input gpio_ipd--io internal pull-down resistor input
   4, Analog input gpio_ain--application ADC analog input, or low power consumption to save power
   5, open-drain output gpio_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 Gpio_out_pp--io output 0-connected gnd, IO Output 1-to VCC, read input value is unknown
   7. Push-pull output of multiplexing function gpio_af_pp--on-chip peripheral function (I²c SCL,SDA)
   8, multiplexing function of the open-drain output gpio_af_od--on-chip peripheral function (Tx1,mosi,miso. SCK. SS)
Seven, 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; Eight, 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 for floating input, with weak pull-up input or with weak pull-down input, and do not enable the pin corresponding to all the reusable function module.
   2, as the ordinary Gpio output: Configure the PIN as required for push-pull output or open-drain output, and do not enable the pin corresponding to all the reusable function module.
   3, as a general analog input: Configure the PIN as analog input mode, and do not enable the pin corresponding to all the reusable function module.
   4, as the input of the built-in peripherals: Configure the PIN as required for the float input, with a weak pull-up input or with a weak pull-down input, while enabling the pin corresponding to a reusable function module.
   5, as the output of the built-in peripheral: Configure the PIN as needed for multiplexing push-pull output or multiplexed open-drain output, while enabling the pin corresponding to all the Multiplexed function module.
   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. For example, to use the STM32F103VBT6 47, 48 feet of the USART3 function, you need to configure 47 feet for multiplexing push-pull output or multiplexed open-drain output, configuration 48 feet for a certain input mode, while enabling the USART3 and maintain i2c2 non-enabling state. If you want to use STM32F103VBT6 's 47 foot as the TIM2_CH3, you need to remap the TIM2 and then configure the corresponding pin in the same way as the multiplexing feature.

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.