1. Select IO mode in STM32
1. Floating input GPIO_IN_FLOATING - floating input, can be used for KEY identification, RX1
2. Pull-up input GPIO_IPU - IO internal pull-up resistor input
3. Pull-down input GPIO_IPD - IO internal pull-down resistor input
4. Analog input GPIO_AIN - ADC analog input, or power saving under low power consumption
5. Open drain output GPIO_OUT_OD - IO output 0 connected to GND, IO output 1, floating, need external pull-up resistor 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 low level or unchanged by the external circuit.
Can read IO input level changes to realize C51's IO bidirectional function
6. Push-pull output GPIO_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 GPIO_AF_PP - on-chip peripheral function (I2C's SCL, SDA)
8. Multiplexed function open-drain output GPIO_AF_OD - on-chip peripheral function (TX1, MOSI, MISO.SCK.SS)
2. STM32 setting example:
1. Simulate I2C using open-drain output _OUT_OD, connected to a pull-up resistor, can correctly output 0 and 1; when reading the value, first GPIO_SetBits(GPIOB, GPIO_Pin_0); pull high,
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 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;
3. There are usually 5 ways to use a pin function, and their configuration methods are as follows:
1. As a normal GPIO input: configure the pin as a floating input, a weak pull-up input or a weak pull-down input as needed, and do not enable all the multiplexing function modules corresponding to the pin.
2. As a normal GPIO output: configure the pin as a push-pull output or an open-drain output as needed, and do not enable all the multiplexing function modules corresponding to the pin.
3. As a normal analog input: configure the pin to analog input mode, and do not enable all the multiplexing function modules corresponding to the pin.
4. As the input of a built-in peripheral: configure the pin as a floating input, a weak pull-up input or a weak pull-down input as needed, and enable a multiplexing function module corresponding to the pin.
5. As the output of built-in peripherals: configure the pin as multiplexed push-pull output or multiplexed open-drain output as needed, and enable all multiplexed function modules corresponding to the pin.
Note:
If there are multiple multiplexed function modules corresponding to the same pin, only one of them can be enabled, and the other modules remain disabled.
For example, if you want to use the USART3 function of pins 47 and 48 of STM32F103VBT6, you need to configure pin 47 as multiplexed push-pull output or multiplexed open-drain output, configure pin 48 as a certain input mode,
enable USART3 and keep I2C2 disabled.
If you want to use pin 47 of STM32F103VBT6 as TIM2_CH3, you need to remap TIM2 and then configure the corresponding pin in the multiplexed function mode.
Previous article:STM32 Getting Started - SysTick clock configuration of the SysTick_Config() function
Next article:STM32 - Setting pull-up and pull-down in GPIO input mode
- Popular Resources
- Popular amplifiers
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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- esp8266 uses oled to play online videos
- Security monitoring multi-channel long-distance transmission problem
- Why does LDMOS conduct without adding gate voltage?
- EEWORLD University Hall----Live Replay: NXP's facial recognition technology solution based on i.MX RT106F
- Function overloading and reentrancy
- Alternative winners in the 5G era
- What Jack Ma said about starting a business...
- Phytec's IMX8Mplus review
- Transplantation of webplayer audio player based on RVB2601
- MCU serial communication program help