About STM32 GPIO mode configuration

Publisher:快乐旅行Latest update time:2017-09-17 Source: eefocusKeywords:STM32  GPIO Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In STM32, there are 8 types of GPIO configurations:

(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
The three types of outputs that we are most exposed to are push-pull output, open-drain output, and pull-up input.

After reading various scattered information, here is a brief summary:

Regarding push-pull output and open-drain output, we can finally summarize them with the simplest diagram:

6ebd493549d90459cb6e7&690

The left side is a push-pull output, and the principle is not explained. The right side can be understood as an open-drain output, which needs to be pulled up. The open-drain output can be used as a current output to improve the load capacity, but an external power supply is required.

Floating input: For floating input, it can be understood that the level state of IO is uncertain and is completely determined by external input. If the pin is floating, the level of the port read is uncertain.

Pull-up input: It is to connect VCC and pull-up resistor externally, and the pull-up resistor also limits the current;

Pull-down input: connect an external pull-down resistor to ground, and the pull-down resistor also limits the current;

As shown below, to detect whether the button is pressed:


 KEY0, KEY1 and KEY2 are low level effective, while WK_UP is high level effective, and there are no pull-up and pull-down resistors externally, so it is necessary to set up pull-up and pull-down inside the STM32. It is easy to know that the pin corresponding to WK_UP should be set as pull-down input, and other pins should be set as pull-up input. (Low level effective is set as pull-up input, high level effective is set as pull-down input)

Analog input: It is the traditional input method, which inputs an analog quantity and can usually be used as ADC input.

Multiplexed open-drain output, multiplexed push-pull output: can be understood as the configuration when the GPIO port is used as a second function (that is, not used as a general IO port) 

For example: when using stm32 serial communication, USART1_TX uses multiplexed push-pull output and USART1_RX uses floating input

For USART1_TX: Because it is a common IO port when the serial port is not available, it is multiplexed. Because there is no pull-up resistor, it is push-pull. Because TX is the data transmission port, it is output. So it is multiplexed push-pull output.

For USART1_RX: Because it is receiving data, the input is left floating.


Finally, let’s summarize the usage:

Select IO mode in STM32
(1) Floating input_IN_FLOATING - floating input, serial port RX1
(2) Pull-up input_IPU - IO external pull-up resistor input
(3) Pull-down input_IPD - IO external pull-down resistor input
(4) Analog input_AIN - ADC analog input, or power saving under low power consumption
(5) Open drain output_OUT_OD - IO output 0 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 (TX1, I2C SCL, SDA)
(8) Multiplexed function open-drain output _AF_OD - on-chip external function (MOSI, MISO.SCK.SS)


Note: Please refer to Baidu Library, Atomic STM32 Development Guide and other materials.


Keywords:STM32  GPIO Reference address:About STM32 GPIO mode configuration

Previous article:About STM32 external interrupt
Next article:STM32 driver Nokia5110

Recommended ReadingLatest update time:2024-11-16 23:46

About the implementation of AD sampling using Stm32 timer + ADC + DMA
Note: This STM32 microcontroller is the STM32F103 series. The ADC of Stm32 has DMA function. This is beyond doubt and is what we use most! However, if we want to sample a signal (such as a pulse signal) at a fixed time (that is, after a period of time, such as 2ms), there are three methods: 1. Use the timer interrupt
[Microcontroller]
STM32__main code analysis
The STM32 startup code mainly allocates the stack and sets the vector table, and then jumps to the __main function. The specific code segment to jump to is as follows:   view plain   copy Reset_Handler PROC                   EXPORT Reset_Handler                    IMPORT __main                   LDR R0, = __mai
[Microcontroller]
STM32__main code analysis
CAN bus communication study notes based on STM32
This article briefly introduces the concepts related to the CAN bus, communication protocols and other knowledge, and uses the bxCAN peripheral that comes with STM32 to perform CAN bus programming experiments, as well as programming experience. 1. Brief introduction to CAN bus 概念:CAN是控制器局域网络(Controller Area Network,
[Microcontroller]
CAN bus communication study notes based on STM32
Design of laser power supply control system based on ARM
  0 Introduction   With the rapid development of the laser industry, lasers have been widely used in industrial processing fields, such as laser cutting, laser marking, laser resistance adjustment, laser heat treatment, etc. In addition, they are also used in the medical field as diagnostic equipment.   Laser weld
[Microcontroller]
Design of laser power supply control system based on ARM
STM32 IAP design example (I)
The project requires the development of a handheld device to upgrade the product software. Current products all use STM32, so it is very convenient to use the IAP function of STM32 to upgrade the software online. The overall requirement is that the host Master sends data to the slave Slave through the CAN interface. A
[Microcontroller]
STM32 IAP design example (I)
STM8 GPIO modes
[Microcontroller]
STM8 GPIO modes
stm32 keeps interrupting and forms a dead loop
I am using the STM32F103 chip and USART2_IRQHandler is always interrupted, causing the program to loop indefinitely. 1. Problem: The interrupt handler of the original program is: void USART2_IRQHandler(void) {   u8 key = 0;   USART_ClearFlag(USART2,USART_FLAG_TC ); //Clear interrupt flag   if(USART_GetITStatus(USART2,
[Microcontroller]
Design of sensor interface module based on STM32
0 Introduction The Internet of Things will be the development trend of the IT industry for a long time in the future. The composition of a complete Internet of Things system or the division of the industrial chain, the industry's relatively unified view is that it should include three levels: terminal devices or subs
[Microcontroller]
Design of sensor interface module based on STM32
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号