1. GPIO configuration
(1) GPIO_Mode_AIN analog input
(2) GPIO_Mode_IN_FLOATING floating input
(3) GPIO_Mode_IPD pull-down input
(4) GPIO_Mode_IPU pull-up input
(5) GPIO_Mode_Out_OD open-drain output
(6) GPIO_Mode_Out_PP push-pull output
(7) GPIO_Mode_AF_OD multiplexed open-drain output
(8) GPIO_Mode_AF_PP multiplexed push-pull output
GPIO_Speed_10MHz maximum output rate 10MHz
GPIO_Speed_2MHz maximum output rate 2MHz
GPIO_Speed_50MHz maximum output rate 50MHz
1.1 In the output mode of the I/O port, there are 3 output speeds to choose from (2MHz, 10MHz and 50MHz). This speed refers to the response speed of the I/O port drive circuit rather than the speed of the output signal. The speed of the output signal is related to the program (the chip has arranged multiple output drive circuits with different response speeds in the output part of the I/O port. Users can choose the appropriate drive circuit according to their needs). By selecting different output drive modules by selecting the speed, the best noise control and power consumption reduction can be achieved. High-frequency drive circuits also have high noise. When a high output frequency is not required, please use a low-frequency drive circuit, which is very helpful to improve the EMI performance of the system. Of course, if you want to output a higher frequency signal, but choose a lower frequency drive module, you may get a distorted output signal.
The key is to match the GPIO pin speed with the application (recommended 10 times or more?). For example:
1.1.1 For the serial port, if the maximum baud rate is only 115.2k, then a 2M GPIO pin speed is enough, which is both power-saving and noise-reducing.
1.1.2 For the I2C interface, if a 400k baud rate is used, if you want to leave a larger margin, then a 2M GPIO pin speed may not be enough, and a 10M GPIO pin speed can be used.
1.1.3 For the SPI interface, if an 18M or 9M baud rate is used, a 10M GPIO pin speed is obviously not enough, and a 50M GPIO pin speed is required.
1.2 When the GPIO port is set as input, the output drive circuit is disconnected from the port, so the output speed configuration is meaningless.
1.3 During reset and just after reset, the multiplexing function is not enabled, and the I/O port is configured as floating input mode.
1.4 All ports have external interrupt capabilities. In order to use the external interrupt line, the port must be configured in input mode.
1.5 The configuration of the GPIO port has a locking function. After the GPIO port is configured, the configuration combination can be locked by the program until the next chip reset.
2. The difference between push-pull output and open-drain output
Push-pull output: can output high or low level, connect digital devices; open-drain output: the output end 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 its ability to absorb current is relatively strong (generally within 20ma).
The push-pull structure generally refers to two transistors that are controlled by two complementary signals respectively, and one transistor is always turned on while the other is turned off.
To achieve line-and-AND, an OC (open collector) gate circuit is required. It is two transistors or MOSFETs with the same parameters, which exist in the circuit in a push-pull manner, each 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.
When the port is configured as output:
Open-drain mode: When outputting 0, N-MOS is turned on, P-MOS is not activated, and output is 0.
When outputting 1, N-MOS is high impedance, P-MOS is not activated, and output is 1 (external pull-up circuit is required); this mode can use the port as a bidirectional IO.
Push-pull mode: When outputting 0, N-MOS is turned on, P-MOS is high impedance, and output is 0.
When outputting 1, N-MOS is high impedance, P-MOS is turned on, and output is 1 (external pull-up circuit is not required).
Simply put, when the open drain is 0, it is connected to GND, and when it is 1, it is floating. When the push-pull is 0, it is connected to GND, and when it is 1, it is connected to VCC.
3. Select IO mode in STM32
(1) Floating input_IN_FLOATING - floating input, can be used for KEY identification, RX1
(2) Pull-up input_IPU - IO internal pull-up resistor input
(3) Pull-down input_IPD - IO internal pull-down resistor input
(4) Analog input_AIN - use ADC analog input, or save power under low power consumption
(5) Open drain output_OUT_OD - IO output 0 is connected to GND, IO output 1, floating, an external pull-up resistor is required to achieve 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. Can read IO input level changes to realize C51 IO bidirectional function
(6) Push-pull output _OUT_PP - IO output 0- connected to GND, IO output 1 - connected to VCC, read input value is unknown
(7) Multiplexed function push-pull output _AF_PP - on-chip external function (I2C SCL, SDA)
(8) Multiplexed function open-drain output _AF_OD - on-chip external function (TX1, MOSI, MISO.SCK.SS)
Example summary:
(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 it 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;
4. IO low power consumption:
Regarding analog input & low power consumption, according to the STM32 low power consumption AN (AN2629) and its source file, in STOP mode, in order to get the lowest power consumption possible, all IOs (including non-A/D input GPIOs) are set to analog inputs.
5. Procedure
(1) Clock:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC, ENABLE);
(2) IO configuration:
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; // IR input
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, & GPIO_InitStructure);
(3) Output and input:
Output 0: GPIO_ResetBits(GPIOB, GPIO_Pin_0)
Output 1: GPIO_SetBits(GPIOB, GPIO_Pin_0)
Input: GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_7)
Previous article:STM32 log summary 1--marquee experiment
Next article:STM32F0 (1) Configuration of system clock RCC
Recommended ReadingLatest update time:2024-11-16 17:49
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- USB Type-C interface desktop monitor dedicated solution - single interface solution
- How is this switching transformer wound?
- How to delete products on Pingtouge's scenario-based Bluetooth Mesh cloud platform
- [Sipeed LicheeRV 86 Panel Review] IV. Failure to compile system image: Struggle and clear direction
- He works overtime, so I work too. I can't run away even if I want to. Have you ever seen such an overtime slogan?
- F28335 PWM trigger ADC sampling code + comments
- 【TouchGFX Design】Installation and simple experience
- How is the output V0 of this op amp derived?
- How to configure AFE940? Does anyone have the documentation?
- The LCD screen uses the ILI9325 screen controller, and the 32-bit board is STM32F103ZET6. After burning the program, only the background is lit,...