STM32GPIO introduction

Started the learning journey of stm32, every step must lay a solid foundation, today I saw the operation of stm32 gpio, write a summary and experience!

What is IO port? Several IO input and output modes of STM32

IO port is input & out input and output, an important method for microcontroller to control peripherals.

The IO port generally has an upper limit of 3.3v, but because some ports have protection diodes, they can tolerate 5v voltage, which is generally marked with TF in the data.

The IO port of stm32 can be configured into 8 modes by software:
Input:
1. Input floating: After the GPIO_Mode_IN_FLOATING
level is entered, it does not go through up and down. After triggering the Schmitt trigger, it enters the input data register, and finally by the CPU Read.
In the floating input state, the level state of IO is uncertain, which is completely determined by the external input (triggered when the input reaches the condition). If the pin is floating, it is uncertain to read the level of the port .
Insert picture description here
2. Input pull-up: GPIO_Mode_IPU originally needs to be triggered at a low level, and there is a pull-up resistor, which makes the port high and achieves anti-interference effect. Only low level is accepted!
Insert picture description here
3. Input pull-down: GPIO_Mode_IPD originally needs to be triggered at a high level, and there is a pull-down resistor, which makes the port low level to achieve anti-interference effect, and only accepts high level!
Insert picture description here
4. Analog input: GPIO_Mode_AIN input has no pull-up and pull-down resistance, and the input is voltage instead of level (the level is only high and low, and the voltage is a continuous value); this input method can be used for AD conversion to accept analog signal
Insert picture description here
output:
5. Open-drain output: GPIO_Mode_Out_OD is
written into the output register first, then passes through the output control circuit, and finally reaches the port ** (in this mode, the IO port can also read the IO port voltage) **
Advantages:
1. The output is equivalent For the collector of the triode, a pull-up resistor is required to obtain a high level, which is suitable for current-type driving, and its ability to absorb current is strong (within 20ma)
2. Open-drain is used to connect devices of different levels to match the level, because when the open-drain pin is not connected to an external pull-up resistor, it can only output low level. If you need to have high level output at the same time Function, 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.
But it also brings a rising edge delay!
3. Multiple open-drain output pins can be connected to one 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 determine the bus occupancy status.
(Supplement: What is "wire AND"?: On a node (line), connect a pull-up resistor to the power supply VCC or VDD and the collector C or drain D of n NPN or NMOS transistors, the emitter of these transistors E or source S is connected to the ground line. As long as one transistor saturates, this node (line) is pulled to the ground level. Because the base injection current (NPN) or gate increase of these transistors High level (NMOS), the transistor will be saturated, so the relationship between the base or gate to this node (line) is NOR logic. If an inverter is added after this node, it is OR logic .)
Insert picture description here
6. Open-drain multiplexing output function:
the difference between GPIO_Mode_AF_OD multiplexing and non-multiplexing is that the non-multiplexing output is controlled by the cpu, and the multiplexing function is to receive output signals from the multiplexing function output port, which can be from the peripheral Accept input signal output.
Insert picture description here
7. Push-pull output: GPIO_Mode_Out_PP
is different from open-drain output in that the MOS tube behind the output control circuit is different!
Advantages: Push-pull circuits are two transistors or MOSFETs with the same parameters, which exist in the circuit in a push-pull manner, each responsible for the positive and negative half-cycle waveform amplification tasks. When the circuit is working, two symmetrical power switches have only one conduction each time. Therefore, the conduction loss is small and the efficiency is high. The output can either sink current to the load or draw current from the load. The push-pull output stage not only improves the load capacity of the circuit, but also increases the switching speed.
Insert picture description here
8. Push-pull multiplexed output function: GPIO_Mode_AF_PP
multiplexed function is similar to before, the output signal source comes from the multiplexed function output port.

IO port summary:

Summary of selecting IO mode in STM32:
(1) Floating input _IN_FLOATING —— Floating input, which can be used for KEY identification
(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 —— ADC analog input, or power saving under low power consumption
(5) Open drain output _OUT_OD —— IO output 0 connected to GND, IO output 1, floating , An external pull-up resistor is required to achieve high output. 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 be changed to a low level or unchanged by an external circuit. Can read IO input level changes to realize STM32's IO bidirectional function

(6) Push-pull output _OUT_PP —— IO output 0-connect to GND, IO output 1-connect to VCC, the read input value is unknown
(7) Push-pull output of multiplex function _AF_PP —— On-chip peripheral function (I2C (SCL, SDA)
(8) Open-drain output of multiplexing function _AF_OD-on-chip peripheral functions (TX1, MOSI, MISO.SCK.SS)

A summary of the effect of punctual atoms on common input and output methods: (I borrowed a wave)

1) As a normal GPIO input: configure this pin as a floating input, a weak pull-up input, or a weak pull-down input as required, and do not enable all the multiplexed function modules corresponding to this pin.
2) As an ordinary GPIO output: configure this pin as push-pull output or open-drain output as required, and do not enable all the multiplexed function modules corresponding to this pin.
3) As a normal analog input: configure this pin as analog input mode, and don't enable all the multiplex function modules corresponding to this pin.
4) As the input of the built-in peripherals: configure the pin as a floating input, a weak pull-up input or a weak pull-down input as required, and enable a multiplex function module corresponding to the pin.
5) As the output of built-in peripherals: configure this pin as a multiplexed push-pull output or multiplexed open-drain output as required, and enable all multiplexed function modules corresponding to this pin.

In the last introduction, each IO port of I has an interrupt capability, as long as it is configured, the external interrupt can be turned on.
There is also a GPIO locking mechanism. After locking, it cannot be modified unless reset. Of course, it needs to be configured in the register. The general introduction is so much. In the next article, I will introduce how to configure GPIO, which must also be learned local.

Guess you like

Origin blog.csdn.net/qq_45396672/article/details/102790540