STM32F103ZET6 —— GPIO

Publisher:WhisperingLightLatest update time:2018-08-14 Source: eefocusKeywords:STM32F103ZET6  GPIO Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The GPIO of STM32 can be configured by software into several different modes. Each I/O port bit can be freely programmed, but the I/O port register must be accessed as a 32-bit word:

A. Chip side:

1. Input:


MODE    Descriptions
Input floatingThe pin is configured to be floating and connected to a Schmitt trigger. The common scenario is external buttons.
Input pull-upThe input is connected to a pull-up resistor to clamp the uncertain signal to a high level
Input DropdownThe input is connected to a pull-down resistor to clamp the uncertain signal to a low level
Analog Input

The signal directly enters the ADC module, which means that the status of the IO port can no longer be read from the input register.







2. Output:


MODE    Descriptions
Open-drain output

The so-called open drain refers to the drain of the MOSFET. When the IO outputs 1, it is suspended and requires an external circuit pull-up resistor to achieve a high-level output (low-level grounding).

It is generally used in situations where the levels do not match, and different level outputs are achieved through external pull-up and pull-down resistors.

Push-pull outputOutput 0 is connected to GND, output 1 is connected to VCC (ie 0=》GND, 1=》3.3V)
Open-drain multiplexingPinMux to other functions
Push-Pull Multiplexing

PinMux to other functions








B. Hardware side:

The corresponding board has two GPIOs connected to the LED:



Uses GPIO Port G Pin13 and Pin14


C. Code side:

The steps required to configure the above two GPIOs to work are as follows:

1. Enable the corresponding GPIO_G clock

2. Configure GPIO_G13/GPIO_G14 as general push-pull output, and configure the port line flip speed to 50M

3. After configuration is complete, set the port output to 1/0 to control the GPIO output.


1. Clock settings:

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, ENABLE); // Here RCC_APB2Periph_GPIOG is (0x01 << 8)

void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)

{

  /* Check the parameters */

  assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));

  assert_param(IS_FUNCTIONAL_STATE(NewState));

  if (NewState != DISABLE)

  {

    RCC->APB2ENR |= RCC_APB2Periph;

  }

  else

  {

    RCC->APB2ENR &= ~RCC_APB2Periph;

  }

}

2. Configure GPIO_G13/GPIO_G14 as general push-pull output, 50M speed


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_InitStructure.GPIO_Speed ​​= GPIO_Speed_50MHz;

 

GPIO_Init(GPIOG, &GPIO_InitStructure);

3. Configure output:


STM32 provides multiple ways to configure GPIO output 1/0, including directly writing 1/0 registers (GPIOx_ODR) to the port, registers specifically set to 1 value (GPIOx_BSRR), and registers specifically set to 0 value (GPIOx_BRR). You can use them at will:


#define LED1_ON GPIO_SetBits(GPIOG, GPIO_Pin_13);  

#define LED1_OFF GPIO_ResetBits(GPIOG, GPIO_Pin_13); 

 

#define LED2_ON GPIO_SetBits(GPIOG, GPIO_Pin_14);  

#define LED2_OFF GPIO_ResetBits(GPIOG, GPIO_Pin_14); 

void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)

{

  /* Check the parameters */

  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));

  assert_param(IS_GPIO_PIN(GPIO_Pin));

  

  GPIOx->BSRR = GPIO_Pin;

}

void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)

{

  /* Check the parameters */

  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));

  assert_param(IS_GPIO_PIN(GPIO_Pin));

  

  GPIOx->BRR = GPIO_Pin;

}

The basic usage is as described above. Later, in the specific peripheral part, the multiplexing function of GPIO will be introduced.


Keywords:STM32F103ZET6  GPIO Reference address:STM32F103ZET6 —— GPIO

Previous article:STM32F103ZET6 — USART
Next article:STM32 Boot mode setting method

Recommended ReadingLatest update time:2024-11-16 12:25

Silicon C8051F340 GPIO port configuration and use
1. Background:         I used C8051 a long time ago. Now I need to use C8051 again. But I forget all the experience I had a year ago.     Basically, it is almost done. Even the most basic GPIO port configuration still requires a new look at the manual, so here is a note to keep in mind for quick reference next time.  
[Microcontroller]
Silicon C8051F340 GPIO port configuration and use
stm32-GPIO operation (library function)
It's rare to have time, so I want to write about the basics of stm32 recently. 8 ways of GPIO  1. Floating input GPIO_IN_FLOATING ——Floating input, can be used for KEY recognition, RX1        2. GPIO_IPU with pull-up input——IO internal pull-up resistor input        3. GPIO_IPD with pull-down input——IO internal pul
[Microcontroller]
STM8 GPIO modes
GPIO_Mode_In_FL_No_IT No interrupt for floating input GPIO_Mode_In_PU_No_IT Pull-up input without interrupt GPIO_Mode_In_FL_IT  Floating input has interrupt  GPIO_Mode_In_PU_IT  Pull-up input has interrupt  GPIO_Mode_Out_OD_Low_Fast  Output open-drain, low level, 10MHz    GPIO_Mode_Out_PP_Low_Fast  Output push-pull, l
[Microcontroller]
NXP-LPC1768 Getting Started: Development Environment Construction and GPIO
1. Environment Construction This project uses ARM's MDK414. Lower versions may result in failure to download debuggers in MDK. The emulator uses SEGGER's JlinkV7. First, create a new project GPIO, select the path to save, and then the chip selection interface will appear Then confirm, create a new main file main.c a
[Microcontroller]
STM32: GPIO basics and corresponding pin operation library functions
USE_STDPERIPH_DRIVER, STM32F10X_HD The English abbreviations of the startup files in the STM32 firmware library Libraries\CMSIS\Core\CM3\startup\arm mean: cl: interconnected product, stm32f105/107 series vl: value product, stm32f100 series xl: ultra-high density (capacity) product, stm32f101/103 series ld: low-densit
[Microcontroller]
GPIO_Write() Function
void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal) {   /* Check the parameters */   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));      GPIOx- ODR = PortVal; } You can assign values ​​to multiple IO ports at one time (note: it is 16 bits!) Example: GPIO_Write(GPIOD,0x0100) //Set PD8 high
[Microcontroller]
Summary of 8 working modes of GPIO in STM32
 1. Push-pull output: can output high and low levels, connect digital devices; push-pull structure generally refers to two transistors being controlled by two complementary signals, one transistor is always turned on while the other is turned off. The high and low levels are determined by the power supply of the IC. A
[Microcontroller]
Summary of 8 working modes of GPIO in STM32
STM32 GPIO related registers (Part 2)
STM32 microcontrollers can only communicate with the outside world if they have ports. Only by learning how to control ports can we make better use of peripherals, establish connections with the outside world, and give full play to our own advantages.          First, let's introduce the basic GPIO related registers:
[Microcontroller]
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号