STM32 GPIO_Mode

Publisher:HeavenlyLoveLatest update time:2017-10-29 Source: eefocusKeywords:STM32  GPIO  Mode Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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)


Keywords:STM32  GPIO  Mode Reference address:STM32 GPIO_Mode

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

D/A playback of MIT-BIH ECG data based on STM32
0 Introduction The ECG signal is one of the earliest bioelectric signals studied and applied in clinical medicine. The analysis and processing of ECG signals can effectively predict heart diseases. How to use ECG data to develop and research related medical equipment is crucial for researchers. ECG data playback is t
[Microcontroller]
D/A playback of MIT-BIH ECG data based on STM32
STM32 learning assert_failed
/******************************************************************************* The firmware library implements run-time error detection by checking the inputs to the library functions. Run-time detection is implemented by using the assert_param macro. All functions that require input parameters use this macro. It ca
[Microcontroller]
STM32 Cube firmware library programming new project
  Cube firmware library is the firmware library currently promoted by ST, and the original standard library can no longer be found for download on its official website. The architecture diagram of Cube firmware library is as follows This new architecture can effectively speed up the engineering progress of software
[Microcontroller]
STM32 Cube firmware library programming new project
STM32 learning seven
USART serial port learning:        This article is mainly about the connection between the stm32 board and the PC machine. Since I am a beginner, I spent a long time thinking about the experiment before I successfully configured the serial port communication. It was very difficult, so it became a blog.           In
[Microcontroller]
STM32 learning seven
STM32 learning record GPIO
The purpose of this study:  1. Learn the basic operations of STM32 chip GPIO  2. Re-encapsulate the relevant functions of GPIO for later development The GPIO schematic diagram of the development board is as follows  As shown in the figure, the LED is connected to PC0-PC7 of GPIOC. STM's GPIO has the following 8 modes
[Microcontroller]
STM32 SysTick system clock super simple timer SysTick
/** * @brief Configures the SysTick. 系统时钟配置函数   main.c  * @param None * @retval None */ void SysTick_Configuration(void) { /* Setup SysTick Timer for 100 msec interrupts */ if (SysTick_Config((SystemCoreClock) / 10))     //     1/10s=100ms {     /* Capture error */      while (1); }    NVIC_SetPriority(Sy
[Microcontroller]
STM32GPIO multiplexing
Basically, each pin of STM32 has 8 configuration modes: 1) Floating input 2) Input with weak pull-up 3) Input with weak pull-down 4) Analog input 5) Push-pull output 6) Open-drain output 7) Multiplexed push-pull output 8) Multiplexed open-drain output There are usually 5 ways to use a pin function, and their configur
[Microcontroller]
Using STM32 general-purpose timer to realize output of two complementary PWM with adjustable duty cycle and frequency
MCU:STM32F334C8T6 PWM, or pulse width modulation, can be used to drive motors, full-bridge circuits, etc. Those who have used STM32 know that its timer can easily achieve PWM output, and the advanced timer's TIMx_CHy and TIMx_CHyN can easily achieve the output of complementary PWM waveforms. Advanced timer resourc
[Microcontroller]
Using STM32 general-purpose timer to realize output of two complementary PWM with adjustable duty cycle and frequency
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号