stm32f103c8t6 blink led

Blink an LED with STM32F103C8T6: A Simple Tutorial

By Mark Lewis
AD

The simplicity and ubiquity of the LED (Light Emitting Diode) make it an ideal component for demonstrating the functionality of a microcontroller like the STM32F103C8T6. In this project, we'll explore how to blink an LED using this popular microcontroller, a hands-on approach to understanding its programming and operations.

Before diving into the specifics, let's ensure you have the necessary hardware and software. You'll need an STM32F103C8T6 development board, an LED, and a breadboard. For software, you'll require the STMicroelectronics STM32CubeMX tool for generating the project files, and an Integrated Development Environment (IDE) like SEGGER Embedded Studio or Makefile-based tools.

Understanding the STM32F103C8T6 Microcontroller

The STM32F103C8T6 is an ARM Cortex-M3 based microcontroller, featuring 64KB of Flash and 20KB of SRAM. It operates at a frequency of up to 72 MHz, providing enough processing power for most entry-level projects.

AD
STM32F103C8T6 Blue Pill: high resolution pinout and specs
STM32F103C8T6 Blue Pill: high resolution pinout and specs
STM32F103C8T6 - Blue Pill
STM32F103C8T6 - Blue Pill
Blink Led with Stm32f103c8 microcontroller keil and Stmcubemx
Blink Led with Stm32f103c8 microcontroller keil and Stmcubemx

One of its salient features is the number of GPIO (General Purpose Input/Output) ports, which make it versatile for various application needs. For our LED blinking project, we'll use one of these ports to control the LED's on-off states.

Setting up the Hardware

Connecting the LED to the STM32F103C8T6 board is straightforward. Insert the LED's long leg (anode) into a breadboard'sWHO section, and the shorter leg (cathode) into the ground section. Connect a resistor (around 220-330 ohms) between the anode and one of the board's GPIO ports, say PA5.

Tutorial/blog to Get Start With STM32 Black Pill and STM Cube IDE to Blink External LED Using HAL Programming.
Tutorial/blog to Get Start With STM32 Black Pill and STM Cube IDE to Blink External LED Using HAL Programming.
00 STM32F103C8 (BluePill) start with Arduino IDE |Led Blink|
00 STM32F103C8 (BluePill) start with Arduino IDE |Led Blink|
FreeRTOS on STM32F103C8T6
FreeRTOS on STM32F103C8T6

It's crucial to use a resistor to limit the current flowing to the LED and prevent damaging the microcontroller. You can adjust the resistor's value to change the LED's brightness.

Configuring the Software

Using STM32CubeMX, generate a project for use with your preferred IDE. In the Configuration tab, ensure that the GPIO port (PA5) is configured as Output. The tool will generate project files that include the necessary headers and .c/.h files for the specifics of your setup.

AD

These generated files will be used in your IDE to create the firmware that controls the GPIO pin, thereby blinking the LED.

External Led Blink Using STM32F401CE
External Led Blink Using STM32F401CE
LED Blinking STM32 Nucleo with Arduino IDE - GPIO Pins
LED Blinking STM32 Nucleo with Arduino IDE - GPIO Pins
Stm32f103c8t6 Arm Stm32 + Gravador/programador St-link V2
Stm32f103c8t6 Arm Stm32 + Gravador/programador St-link V2
STM32F103C8T6 Core Board, Upgrade from 51 Microcontroller Development Board, 51 to ARM STM32
STM32F103C8T6 Core Board, Upgrade from 51 Microcontroller Development Board, 51 to ARM STM32
Interfacing I2C LCD with STM32F103C8T6 | STM32 I2C LCD Tutorial
Interfacing I2C LCD with STM32F103C8T6 | STM32 I2C LCD Tutorial
Blink Blonk
Blink Blonk

Programming the LED Blink Sequence

The blinking LED's functionality can be achieved by toggling the GPIO pin between low and high states. The STM32's ARM Cortex-M core allows for efficient management of this task.

You can use the HAL (Hardware Abstraction Layer) functions generated by STM32CubeMX, specifically `HAL_GPIO_TogglePin()`, to simplify the process. Wrapping this function inside a loop will produce the desired blinking effect.

AD

Writing the Blink Function

In your main.c file, create a function named `blinkLED()`, which will contain the looping logic for toggling the GPIO pin. Include necessary headers for the GPIO functions and your specific GPIO port definition:

STM32F103C8T6 STM32F103CBT6 ARM STM32 Minimum System Learning Development Board Module For Arduino 32F103C8T6 - AliExpress
STM32F103C8T6 STM32F103CBT6 ARM STM32 Minimum System Learning Development Board Module For Arduino 32F103C8T6 - AliExpress
Blinkenlights To Bootloader: A Guide To STM32 Development
Blinkenlights To Bootloader: A Guide To STM32 Development
STM32 Nucleo GPIO Pins with LED Blinking using STM32CubeIDE
STM32 Nucleo GPIO Pins with LED Blinking using STM32CubeIDE
BLINKING LED CONNECTED EXTERNALLY USING STM32 CUBE IDE
BLINKING LED CONNECTED EXTERNALLY USING STM32 CUBE IDE
STM32F103C8T6 development board - Share Project - PCBWay
STM32F103C8T6 development board - Share Project - PCBWay
11. Install STM32 CubeIDE and LED blink program for Windows (OpenOCD included)
11. Install STM32 CubeIDE and LED blink program for Windows (OpenOCD included)
STM32F103 PCB STM32 MCU family developer board schematic STM32F103 PCB STM32 MCU family deve...
STM32F103 PCB STM32 MCU family developer board schematic STM32F103 PCB STM32 MCU family deve...
STM32: First Blinking LED Project
STM32: First Blinking LED Project
BLINKIG
BLINKIG
Tinkercad Blinking LED Lights - Tinkercad
Tinkercad Blinking LED Lights - Tinkercad
How to Blink An LED Bulb Using ESP32 Board
How to Blink An LED Bulb Using ESP32 Board
Blinking a LED in Multiple Sequences Using STM 32
Blinking a LED in Multiple Sequences Using STM 32

#include "stm32f1xx_hal.h" #include "main.h" void blinkLED(void) { while (1) { HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); // Toggles PA5 HAL_Delay(500); // Delays for 500ms or 0.5 seconds } }

The `HAL_Delay()` function ensures that the state remains constant for a specified duration, creating the blinking effect.

AD

Calling the Blink Function

In the `main()` function, call the `blinkLED()` function to start the LED blinking cycle as soon as the microcontroller boots.

int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); blinkLED(); // Calls the LED blinking function while (1) {} }

Now, when you program your STM32F103C8T6 board with this firmware, the LED connected to PA5 should alternate between on and off states, demonstrating a simple and effective blinking LED project using the STM32 microcontroller.

As you've now mastered blinking an LED with the STM32F103C8T6 microcontroller, you can build upon this foundation to explore more complex projects, such as pulsating LEDs, LED strips, or even interfacing with other sensors and displays. Happy experimenting!

AD