Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

STM32F103C8T6 Battery-Powered LED Blinker

View and Edit Project In Cirkit DesignerImage of STM32F103C8T6 Battery-Powered LED Blinker

Circuit Documentation

Summary

This circuit consists of an STM32F103C8T6 microcontroller, a red LED, and a 2 x AA battery mount. The microcontroller controls the LED, turning it on and off with a 1-second interval. The circuit is powered by the 2 x AA battery mount.

Component List

STM32F103C8T6

LED: Two Pin (red)

2 x AA Battery Mount

Wiring Details

STM32F103C8T6

LED: Two Pin (red)

2 x AA Battery Mount

Code Documentation

Main Code

#include "stm32f1xx_hal.h"

void SystemClock_Config(void);
static void MX_GPIO_Init(void);

int main(void)
{
    // Initialize the HAL Library
    HAL_Init();

    // Configure the system clock
    SystemClock_Config();

    // Initialize all configured peripherals (GPIO)
    MX_GPIO_Init();

    // Main loop
    while (1)
    {
        // Turn on the LED
        HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);
        
        // Add a delay to keep the LED on
        HAL_Delay(1000); // 1 second delay

        // Turn off the LED
        HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);

        // Add a delay to keep the LED off
        HAL_Delay(1000); // 1 second delay
    }
}

void SystemClock_Config(void)
{
    // System Clock Configuration code here
    // This is usually auto-generated by STM32CubeMX
}

static void MX_GPIO_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStruct = {0};

    // GPIO Ports Clock Enable
    __HAL_RCC_GPIOA_CLK_ENABLE();

    // Configure GPIO pin Output Level
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);

    // Configure GPIO pin : PA0
    GPIO_InitStruct.Pin = GPIO_PIN_0;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}

This code initializes the STM32F103C8T6 microcontroller, configures the system clock, and sets up GPIO pin A0 as an output. The main loop toggles the LED connected to pin A0 on and off with a 1-second delay.