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
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- The difference between variable frequency power supply and inverter
- PWM output of MPS430 microcontroller
- PCB Design Considerations
- LD array driver power supply with temperature adaptive regulation
- [Sipeed LicheeRV 86 Panel Review] - 1. Lichee RV 86 Panel powered on for the first time
- Configuration and use of TI C2000 TMS320F28379D SCID SCIB
- [Old post 3] You want to specify the address of a variable? In fact, it needs a shared memory mechanism
- Low-power multi-protocol chip ZigBee/6LoWPAN/BLE/Thread chip CC2652
- Can the program configured in stm32cubeMX be used for GD32 chip?
- Share a STLINK V2_1 PCB project, which can be directly sampled and produced