stm32f103c8t6 led blink example

STMP32F103C8T6 LED Blink Tutorial

By Robert Anderson
AD

Are you eager to dive into the world of microcontrollers and create your first LED blinking project? The STM32F103C8T6, a popular choice among hobbyists and professionals alike, is an excellent starting point for such a venture. This article will guide you through setting up an LED blinking example on this versatile microcontroller, ensuring you understand the process and gain hands-on experience.

The STM32F103C8T6, based on the ARM Cortex-M3 core, offers an array of features that make it perfect for various applications. For our LED blinking project, we'll focus on its powerful GPIO pins and simple programming interface, allowing us to control LEDs with ease.

Setting Up the Development Environment

Before diving into the code, ensure you have the necessary software and hardware ready.

AD
STM32F103C8T6 Blue Pill: high resolution pinout and specs - Mischianti
STM32F103C8T6 Blue Pill: high resolution pinout and specs - Mischianti
Input Output Ports 8051 Microcontroller: LED Blinking Example
Input Output Ports 8051 Microcontroller: LED Blinking Example
External Led Blink Using STM32F401CE
External Led Blink Using STM32F401CE

1. **Hardware Components:** - STM32F103C8T6 development board (e.g., Blue Pill) - LED (any color) - Breadboard and jumpers

Installing STM32CubeMX

STM32CubeMX is a free and user-friendly software tool from STMicroelectronics that helps configure and initialize STM32 microcontrollers. It simplifies projects by generating initialization code and driver libraries tailored to your specific use case.

Efficient LED Blinking for Embedded Systems
Efficient LED Blinking for Embedded Systems
ESP32 GPIO with ESP-IDF with LED Blinking example
ESP32 GPIO with ESP-IDF with LED Blinking example
STM32F103C8T6 - Purple Pill
STM32F103C8T6 - Purple Pill

1. Download and install STM32CubeMX from the official STMicroelectronics website. 2. Open STM32CubeMX and select "STM32F1" as the series and "STM32F103x8" as the model. 3. Configure the project by enabling the GPIO pin connected to your LED and setting it as output. 4. Generate the project for your preferred IDE (e.g., SEGGER Embedded Studio, IAR Embedded Workbench, or Makefile).

Preparing the Hardware

Connect the LED to your STM32F103C8T6 development board

AD

1. Connect one leg of the LED to any GPIO pin you enabled in STM32CubeMX (e.g., PA5). Ensure the long leg (anode) is connected to the pin, and the short leg (cathode) to GND. 2. Power up the board and ensure the LED is not illuminated initially.

Proteus Simulation for LED Blinking Project
Proteus Simulation for LED Blinking Project
FreeRTOS on STM32F103C8T6
FreeRTOS on STM32F103C8T6
Blink Led with Stm32f103c8 microcontroller keil and Stmcubemx
Blink Led with Stm32f103c8 microcontroller keil and Stmcubemx
STM32F103C8T6 - Blue Pill
STM32F103C8T6 - Blue Pill
STM32 Nucleo GPIO Pins with LED Blinking using STM32CubeIDE
STM32 Nucleo GPIO Pins with LED Blinking using STM32CubeIDE
Blink Blonk
Blink Blonk

The LED Blinking Algorithm

With the setup complete, let's focus on writing the code to make your LED blink.

We'll use a simple delay-based algorithm, making the LED toggle its state every second.

AD

Including Necessary Headers

At the beginning of your main.c file, include the necessary headers.

Getting Started with STM32 (Blue Pill) using Arduino IDE: Blinking LED
Getting Started with STM32 (Blue Pill) using Arduino IDE: Blinking LED
LED Blinking STM32F4 Discovery Board - Control GPIO with HAL Driver
LED Blinking STM32F4 Discovery Board - Control GPIO with HAL Driver
How to Blink An LED Bulb Using ESP32 Board
How to Blink An LED Bulb Using ESP32 Board
Interfacing I2C LCD with STM32F103C8T6 | STM32 I2C LCD Tutorial
Interfacing I2C LCD with STM32F103C8T6 | STM32 I2C LCD Tutorial
STM32: First Blinking LED Project
STM32: First Blinking LED Project
BLINKIG
BLINKIG
3. STM32. Програмування STM32F103. GPIO - Avislab - сайт для палких паяльників
3. STM32. Програмування STM32F103. GPIO - Avislab - сайт для палких паяльників
11. Install STM32 CubeIDE and LED blink program for Windows (OpenOCD included)
11. Install STM32 CubeIDE and LED blink program for Windows (OpenOCD included)
Blinkenlights To Bootloader: A Guide To STM32 Development
Blinkenlights To Bootloader: A Guide To STM32 Development
ESP32 LED Blink Simulation Project for Students
ESP32 LED Blink Simulation Project for Students
Blinking LED Circuit with Schematics and Explanation
Blinking LED Circuit with Schematics and Explanation
Simple Blinking LED Circuit
Simple Blinking LED Circuit
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...
Sequential LED Blinking using 555 Timer in Proteus ISIS
Sequential LED Blinking using 555 Timer in Proteus ISIS

```c #include "stm32f1xx_hal.h" ```

Initializing GPIO Pins

In the main function, initialize the GPIO pin connected to the LED as an output.

AD

```c int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); GPIO_PinState PinState = GPIO_PIN_RESET; while (1) { // LED toggling code goes here } } ```

Toggling the LED State

Now, let's add the code to toggle the LED state every second.

1. Within the while loop in the main function, add the following code: ```c HAL_Delay(1000); // Delay for 1000 milliseconds (1 second) PinState = !PinState; // Toggle the PinState variable HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, PinState); // Write the new state to the GPIO pin ``` 2. Replace `GPIOA` and `GPIO_PIN_5` with your chosen GPIO port and pin, respectively.

With this code, your LED will now blink every second. Congratulations on completing your first LED blinking project using STM32!

As you progress in your microcontroller journey, consider exploring more advanced features like PWM (Pulse Width Modulation) to control LED brightness, or interfacing with sensors and other peripherals. The world of embedded systems is vast and full of exciting possibilities. Happy creating!

AD