STM32 IO mode
(1) Floating input_IN_FLOATING——Floating input, can be used for KEY recognition, 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 - Use ADC analog input or save power in low power mode
(5) Open-drain output_OUT_OD - IO output 0 is connected to GND, IO output 1 is left floating, and an external pull-up resistor is required to achieve a 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. The IO input level change can be read to realize the IO bidirectional function of C51
(6) Push-pull output_OUT_PP - IO output 0 - connected to GND, IO output 1 - connected to VCC, the read input value is unknown
(7) Multiplexed function push-pull output _AF_PP - on-chip external function (SCL, SDA of I2C)
(8) Multiplexed function open-drain output _AF_OD - on-chip external functions (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 high, then you can read the value of IO; use
GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0);
(2) If there is no pull-up resistor, IO is high by default. If you need to read the value of IO, you can use
With pull-up input_IPU, floating input_IN_FLOATING and open-drain output_OUT_OD;
The difference between push-pull output and open-drain output
Push-pull output: can output high and low levels, 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 being controlled by two complementary signals, and one transistor is always turned on while the other is turned off.
To realize line-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 outputs 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 output is 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 (no external pull-up circuit is 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.
GPIO usage initialization configuration
void GPIO_config(void)
{
/*Define a GPIO_InitTypeDef type structure*/
GPIO_InitTypeDef GPIO_InitStructure;
/*Turn on LED related GPIO peripheral clock*/
RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOH, ENABLE);
/*Select the GPIO pin to be controlled*/
GPIO_InitStructure.GPIO_Pin = LED1_PIN;
/*Set the pin mode to output mode*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
/*Set the output type of the pin to push-pull output*/
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
/*Set the pin to pull-up mode*/
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
/*Set the pin rate to 2MHz */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
/*Call library function to initialize GPIO using GPIO_InitStructure configured above*/
GPIO_Init(GPIOH, &GPIO_InitStructure);
/*Set the corresponding pin*/
GPIO_SetBits(GPIOH,LED1_PIN);
}
Configuration to be performed using GPIO
1. Use GPIO_InitTypeDef to define the GPIO initialization structure variable so that it can be used to store GPIO configuration below.
2. Assign value to RCC register and call library function RCC_AHB1PeriphClockCmd to enable
GPIO configurable mode
Input floating
Input pull-up
Input Dropdown
Simulation function
Open-drain output with pull-up or pull-down capability
Push-pull output with pull-up or pull-down capability
Alternate function push-pull with pull-up or pull-down capability
Alternate-function open-drain with pull-up or pull-down capability
GPIO Port Mode
GPIO_Mode_IN = 0x00, /*!< GPIO Input Mode */
GPIO_Mode_OUT = 0x01, /*!< GPIO Output Mode */
GPIO_Mode_AF = 0x02, /*!< GPIO Alternate function Mode */
GPIO_Mode_AN = 0x03 /*!< GPIO Analog Mode */
00: Input (reset state)
01: General output mode
10: Multiplexing function mode
11: Simulation mode
GPIO port output type
GPIO_OType_PP = 0x00, //0: output push-pull (reset state)
GPIO_OType_OD = 0x01 //1: Output open drain
In input mode, GPIO_OType has no effect, but this variable should still be assigned a value.
GPIO port output speed
00: 2 MHz (low speed)
01: 25 MHz (medium speed)
10: 50 MHz (Fast)
11: 100 MHz at 30 pF (high speed)
GPIO port pull-up/pull-down register
00: No pull-up or pull-down
01: Pull-up
10: Pull down
11: Reserved
GPIO port input data register
GPIO port output data register
GPIO Port Set/Reset Register
GPIO Port Configuration Lock Register
GPIO multiplexing function low register
Previous article:STM32F407 timer clock frequency
Next article:STM32 GPIO mode summary
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- 11 examples to teach you how to deal with servo motor jitter problems
- Low Power Consumption Design Strategy for Single Chip Microcomputer System
- This picture can explain AD DC very well.
- Ten PLCs detect heater disconnection circuit diagram
- AD16 suddenly cannot import DDB files
- Why Use a 24-Bit Converter Instead of Multiple 12-Bit Devices
- FPGA_100 Days Tour_Binary to Gray Code to Binary
- [Silicon Labs BG22-EK4108A Bluetooth Development Evaluation] + Development Board Power Consumption Detection and Comparison
- Temperature Problems Solved for You (II) System Temperature Monitoring
- 【DIY Creative LED】Testing the main functions of the circuit