STM32F429 GPIO usage

Publisher:SereneHeartLatest update time:2019-01-30 Source: eefocusKeywords:STM32F429  GPIO Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

Keywords:STM32F429  GPIO Reference address:STM32F429 GPIO usage

Previous article:STM32F407 timer clock frequency
Next article:STM32 GPIO mode summary

Latest Microcontroller Articles
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号