STM32 GPIO pin mode settings and usage

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

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.

Keywords:STM32  GPIO Reference address:STM32 GPIO pin mode settings and usage

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

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号