841 views|4 replies

1456

Posts

1

Resources
The OP
 

[STM32F4-discovery development board review] Basic use of GPIO ports [Copy link]

The GPIO port is the entry point for hardware development. To understand the basic usage of the GPIO port, you can start with the use of LED and KEY.

There are 2 LEDs and 1 KEY on the development board, and the circuit is shown in Figure 1 and Figure 2.

Figure 1 LED circuit

Figure 2 KEY circuit

From the figure, we can see that the connection relationship between it and the development board is:

LD3---PG13

LD4--- PG14

KEY--- PA0

When the LED is turned on, the corresponding pin is required to output a high level. For KEY, it is a high level when the key is pressed.

The function to implement LED and KEY initialization is:

void gpio_Init(void )
{
  GPIO_InitTypeDef  GPIO_InitStruct;
  __HAL_RCC_GPIOG_CLK_ENABLE();
  GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
  
  __HAL_RCC_GPIOA_CLK_ENABLE();
  GPIO_InitStruct.Pin = GPIO_PIN_0;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}

The main program to realize the button control of LED light on and off is:

int main(void)
{
    SystemClock_Config();
	gpio_Init();
	while (1)
    {
		   if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0)==1)
		   {
		         HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_SET); 
		         HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, GPIO_PIN_SET); 
		   }
		   else
		   {
                 HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_RESET);
                 HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, GPIO_PIN_RESET); 		
		   }
    }
}

After the program is compiled and downloaded, the result is shown in Figure 3, indicating that the program is effective.

Figure 3 Control effect

Later, the GPIO port will be used to realize the display drive of the OLED screen.

This post is from stm32/stm8

Latest reply

Looking at this USB port, we can infer that this board should be more than 10 years old.   Details Published on 2023-9-19 17:21
 

6570

Posts

0

Resources
2
 

The GPIO port basically uses one button and two lights, which is easier to control.

This post is from stm32/stm8

Comments

Haha, a towering building rises from the ground.  Details Published on 2023-9-18 08:45
 
 

1456

Posts

1

Resources
3
 
Jacktang posted on 2023-9-18 07:28 The GPIO port basically uses one button and two lights, which is easier to control

Haha, a towering building rises from the ground.

This post is from stm32/stm8
 
 

7422

Posts

2

Resources
4
 

Looking at this USB port, we can infer that this board should be more than 10 years old.

This post is from stm32/stm8

Comments

If it is older, it can be collected as an antique!!!  Details Published on 2023-9-20 18:30
 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 

1456

Posts

1

Resources
5
 
freebsder posted on 2023-9-19 17:21 Looking at this USB port, we can infer that this board should be stored for more than 10 years

If it is older, it can be collected as an antique!!!

This post is from stm32/stm8
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list