**I. Overview**
**1. Introduction to LED**
A Light Emitting Diode (LED) is a semiconductor device that emits light when an electric current passes through it. LEDs are commonly used in various applications due to their efficiency, low power consumption, and long lifespan. They are typically available in red, green, and yellow colors. The reverse breakdown voltage of an LED is usually around 5V, which means applying a voltage higher than this can damage the component.
The forward voltage-current characteristic curve of an LED is steep, so it's essential to use a current-limiting resistor in series with the LED to prevent excessive current from flowing through it. The value of the resistor can be calculated using the formula:
**R = (E - UF) / IF**
Where:
- **E** is the supply voltage,
- **UF** is the forward voltage drop across the LED,
- **IF** is the operating current of the LED.
LEDs are widely used in electronic circuits, home appliances, meters, and other devices as indicators for power status or signal levels.
**2. STM32 GPIO Introduction**
STM32F4 microcontrollers feature General Purpose Input/Output (GPIO) ports that offer flexible configuration options. Each GPIO port consists of four 32-bit configuration registers (MODER, OTYPER, OSPEEDR, and PUPDR), two 32-bit data registers (IDR and ODR), one 32-bit reset register (BSRR), one 32-bit lock register (LCKR), and two 32-bit multiplex function selection registers (AFRH and AFRL).
GPIO pins can be configured in eight different modes:
- **Floating input**: The pin is in a high-impedance state, often used for communication protocols.
- **Pull-up input**: A built-in pull-up resistor ensures a default high level when no signal is applied.
- **Analog input**: The pin is used as an analog input, disabling internal resistors and Schmitt triggers.
- **Open-drain output**: The pin can only sink current, requiring an external pull-up resistor to achieve a high level.
- **Push-pull output**: The pin can both source and sink current, providing a full voltage swing.
- **Open-drain multiplexed output**: Used when the pin is part of a peripheral function, with the output controlled by the peripheral module.
- **Push-pull multiplexed output**: Similar to push-pull mode, but the output is driven by an internal peripheral rather than the GPIO itself.
These modes allow developers to tailor the behavior of each pin according to the application’s requirements.
**II. Hardware Circuit**
In the iCore3 dual-core development board, three separate RGB LEDs are connected to the STM32F407 microcontroller. Each LED is connected through a 1kΩ current-limiting resistor. Specifically, the red LED is connected to PI5, the green LED to PI6, and the blue LED to PI7. This setup allows individual control of each color via the corresponding GPIO pin.

**III. Experimental Principle**
In this experiment, the three-color LED is controlled using three GPIO pins of the STM32 microcontroller. The GPIOs are configured in push-pull output mode, allowing them to drive the LEDs directly. When the GPIO outputs a high level, the LED turns off; when it outputs a low level, the LED turns on. By alternating the states of the three GPIOs, the RGB LED can display different colors sequentially.
**IV. Source Code**
**1. Main Function**
```c
/*
* Name : main
* Description : Main program entry point
* Author : ysloveivy
* History
* --------------------
* Rev : 0.00
* Date : 11/21/2015
* create.
* --------------------
*/
int main(void)
{
int i;
Led.initialize();
// Three-color LEDs flash alternately
while(1){
LED_RED_ON;
LED_GREEN_OFF;
LED_BLUE_OFF;
for(i = 0; i < 10000000; i++);
LED_RED_OFF;
LED_GREEN_ON;
LED_BLUE_OFF;
for(i = 0; i < 10000000; i++);
LED_RED_OFF;
LED_GREEN_OFF;
LED_BLUE_ON;
for(i = 0; i < 10000000; i++);
}
}
```
**2. GPIO Initialization**
```c
/*
* Name : initialize
* Description : Initialize the GPIO for the LED
* Author : ysloveivy
* History
* --------------------
* Rev : 0.00
* Date : 11/21/2015
* create.
* --------------------
*/
static int initialize(void)
{
GPIO_InitTypeDef GPIO_uInitStructure;
// Enable clock for GPIOI
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI, ENABLE);
// Configure GPIO pins for LED
GPIO_uInitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_uInitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_uInitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_uInitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_uInitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOI, &GPIO_uInitStructure);
// Set all LEDs to OFF initially
GPIO_SetBits(GPIOI, GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7);
return 0;
}
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
{
// This function initializes the selected GPIO pins based on the provided structure.
}
```
The `GPIO_InitTypeDef` structure includes the following parameters:
- `GPIO_Pin`: Specifies which pins are being initialized.
- `GPIO_Mode`: Sets the operating mode of the pin (input/output, etc.).
- `GPIO_Speed`: Configures the speed of the pin.
- `GPIO_OType`: Determines whether the output is push-pull or open-drain.
- `GPIO_PuPd`: Enables or disables internal pull-up or pull-down resistors.
**V. Experimental Phenomenon**
When the program runs, the three-color LED connected to the ARM section of the iCore3 dual-core board (labeled as "ARM·LED" on the PCB) will cycle through red, green, and blue lights sequentially, demonstrating the functionality of the STM32 GPIO in controlling external components.
Non Electronic Passive Stylus Pen,Universal Passive Stylus Pen,Passive Touch Stylus Pen,Simple Passive Stylus Pen
Shenzhen Ruidian Technology CO., Ltd , https://www.wisonen.com