STM32 learning: the simplest GPIO operation steps

Publisher:转眼人老Latest update time:2018-09-06 Source: eefocusKeywords:STM32  GPIO Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The ".c" library functions needed are stm32f10x_gpio.c and stm32f10x_rcc.c
 
1. Start the RCC (reset always control) of the corresponding Port x
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOx, ENABLE);
    x can be A to G, GPIO is controlled by APB2 (high-speed peripheral) clock
2. Assign values ​​to the three parameters in the GPIO initial structure (the structure name needs to be defined before the program: "GPIO_InitTypeDef GPIO_InitStructure;")
    The three parameters are
    pins: GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;
    speed: GPIO_InitStructure.GPIO_Speed=GPIO_Speed_2MHz;
    mode: GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
    The values ​​of the three parameters can be found in the "Firmware Function Library"
3. Use the GPIO initialization function GPIO_Init(GPIOx,&GPIO_InitStructure) to define the previously assigned structure to Port x.
    x can be A to G;
4. Then you can use the GPIO_ResetBits(GPIOx,GPIO_Pin_y) function to set the pin to 0 
     or use the GPIO_SetBits(GPIOx,GPIO_Pin_y) function to set the pin to 1
     x can be: A to F;
     y can be: 0 to 15; multiple values ​​can be separated by "|", such as: GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9
5. You can also use the GPIO_ReadInputDataBit(GPIOx,GPIO_Pin_y) function to read the value of the input pin
      or use the GPIO_ReadOutputDataBit(GPIOx,GPIO_Pin_y) function to read the value of the output pin.
      x can be: A to F;
      y can be: 0 to 15; multiple values ​​can be separated by "|", such as: GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9
Note: a) The functions for reading the entire Port value are GPIO_ReadInputData(GPIOx) and GPIO_ReadOutputData(GPIOx)
        b) The function for writing the entire Port value is GPIO_Write(GPIOx, value)
        c) Generally, after starting according to the first 3 steps, the set GPIO pins will be set to 0 (low level)

Keywords:STM32  GPIO Reference address:STM32 learning: the simplest GPIO operation steps

Previous article:STM32 (II) GPIO operation (1) - input and output operation
Next article:STM32 GPIO principle: input and output control

Recommended ReadingLatest update time:2024-11-23 11:19

For STM32 software reset
For STM32, there are two ways to reset the software:   1) Use the official software library     The system reset function is directly provided in the stm32f10x_nvic.c file of the official software library   /******************************************************************************* * Function Name  : NVIC_Generat
[Microcontroller]
Causes and solutions for insufficient STM32 stack allocation space
STM32 insufficient stack space issue        Let me first state the conclusion. Taking STM32F103RCT6 as an example, the initial stack space is 1KB and the heap space is 512Byte. If the dynamic memory allocation requirement is too high, the heap space needs to be adjusted manually. The stack space size can be set at the
[Microcontroller]
stm32.cube(六)——HAL.FLASH
1. On-chip Flash Features 1.1 Flash structure diagram   My development board is stm32f103xx, so the on-chip flash main memory size is 128K, and a single page is 1K. Different chips have different flash sizes and page sizes. Main Memory The area used to store Rom programs and burn them. Of course, it can also store o
[Microcontroller]
STM32 serial communication
Purpose: Use serial port 1 to continuously print a message to the computer, receive data from the serial port at the same time, and send the sent data directly back to the computer.   experiment platform: Color screen development board based on STM32F103C8T6   Hardware interface:                
[Microcontroller]
STM32 Series 26 - Capacitive Touch Screen
Touch screen classification: Resistive: accurate positioning, single-point touch Capacitive induction: Capacitive induction: supports multi-touch, but is more expensive. Most widely used in industry Infrared: Low price, but the frame is fragile, prone to light interference, and distortion on curved surfaces Surfac
[Microcontroller]
STM32 Series 26 - Capacitive Touch Screen
Summary of stm32 serial communication debugging
This article is divided into two parts, namely "Serial port initialization taking USART1 as an example" and "Problems encountered in debugging" Serial port initialization using USART1 as an example This program calls the firmware library that comes with stm32. The specific files in the project are shown in the figure
[Microcontroller]
Summary of stm32 serial communication debugging
stm32 uses PWM wave interrupt to accurately control the number of waves
1. If you want to get the following waveform: The period of each wave is 25us, and the frequency of a group of waves is 10HZ Implementation ideas: When implementing, use CH1 of TIM1 and CH1 of TIM2, use the interrupt of TIM15, and interrupt once every 100 ms. In the interrupt service function, turn on the out
[Microcontroller]
stm32 uses PWM wave interrupt to accurately control the number of waves
Please pay attention to the initialization sequence when using DMA mode for STM32 AD
I accidentally saw this post today. It was posted by the moderator a long time ago~~~ I suddenly realized that my data seemed to have been in place. Seeing this, I tried it again and found that it was the same no matter where I put DMA_Cmd(DMA1_Channel1, ENABLE);~~~ This is the original post: Please pay attention to
[Microcontroller]
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号