Three, GPIO introduction

1. Introduction to GPIO

(1) What is GPIO

GPIO (general purpose intput output) is the abbreviation of general purpose input and output port, whose input and output can be controlled by software. The GPIO pins of the STM32 chip are connected with external devices to realize the functions of communication, control and data collection with the outside.

(Two) STM32 pin classification

Power supply pins, crystal oscillator pins, reset pins, download pins, BOOT pins, GPIO pins

(3) How to find GPIO function

Check the data development manual of STM32. Note that when the port is marked with FT, it means that it can tolerate 5V voltage. If it is marked with TTA, it means that it can only accept 3.3V voltage. Be careful not to connect to 5V, it will burn out.

Two, GPIO structure

(1) GPIO basic structure

Basic structure of I/O port bits

Note that IO ports cannot drive high-power devices, such as motors, and need to add drive circuits

(2) GPIO working mode

1. Input mode

Input floating: the up and down switches are not used

Input pull-up: pull-up switch under VDD

Input pull-down: pull-down switch above VSS

Analog input

2. Output mode

Open drain output: basic output, control output through P-MOS and N-MOS tube

Open drain multiplexed output: open drain output in multiplexed mode

Push-pull output: basic output, control output through P-MOS and N-MOS tube

Push-pull multiplexed output: Push-pull output in multiplexed mode

3. Summary:

(1) Push-pull output: a. It can output high and low levels for connecting digital devices. The high level is determined by VDD and the low level is determined by VSS; b. Push-pull structure means that two transistors receive two complementary signals Control is always when one is turned on and the other is turned off. The advantages are high switching efficiency, large current, and strong driving ability; c. When the output is high, the current is output to the load, which is called sink current, which can be understood as pushing and low output When level, the load current flows to the chip, which is called pull current, that is, pull

(2) Open drain output: a. It can only output low level, not high level. If you want to output a high level, you need an external pull-up; b. The open-drain output has a "wire-AND" function, one is low and all are low, mostly used for I2C and SMBUS buses

(3) GPIO initialization steps

For specific registers, please refer to STM32Flxx Chinese Reference Manual

(1) Determine the working mode and speed of GPIO (via configuration registers GPIOx_CRL and GPIOx_CRH);

(2) The specific content to be output (set reset register: BSRR and data output register: ODR)
GPIOx_CRL manages the lower eight pins, GPIOx_CRH manages the upper eight pins, the working speed is mainly the output mode, and the output frequency can be configured

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/qq_40836442/article/details/109532999