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

How to Use STM32F103: Examples, Pinouts, and Specs

Image of STM32F103Design with STM32F103 in Cirkit Designer

Introduction

The STM32F103 is a 32-bit microcontroller developed by STMicroelectronics, based on the ARM Cortex-M3 core. It is widely recognized for its low power consumption, high performance, and extensive peripheral set. This microcontroller is part of the STM32 family and is designed to meet the needs of a variety of embedded applications, including industrial automation, consumer electronics, IoT devices, and motor control systems.

Explore Projects Built with STM32F103

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of Solar-Powered STM32-Based Automation System with Matrix Keypad and RTC: A project utilizing STM32F103 in a practical application
Solar-Powered STM32-Based Automation System with Matrix Keypad and RTC

This circuit features an STM32F103C8T6 microcontroller interfaced with a membrane matrix keypad for input, an RTC DS3231 for real-time clock functionality, and a 16x2 I2C LCD for display. It controls four 12V geared motors through two MD20 CYTRON motor drivers, with the motor power supplied by a 12V battery regulated by a buck converter. The battery is charged via a solar panel connected through a solar charge controller, ensuring a renewable energy source for the system.

Open Project in Cirkit Designer

Common Applications and Use Cases

Technical Specifications

Key Technical Details

Pin Configuration and Descriptions

Below is an example of the pin configuration for the STM32F103 in the LQFP48 package:

Pin Number Pin Name Function Description
1 VDD Power Supply Positive power supply (2.0V to 3.6V)
2 VDDA Analog Power Supply Power supply for ADC and DAC
3 PA0 GPIO/ADC_IN0 General-purpose I/O or ADC input channel
4 PA1 GPIO/ADC_IN1 General-purpose I/O or ADC input channel
5 PA2 GPIO/USART2_TX General-purpose I/O or USART2 transmit
6 PA3 GPIO/USART2_RX General-purpose I/O or USART2 receive
7 PA4 GPIO/SPI1_NSS/ADC_IN4 General-purpose I/O or SPI1 chip select
8 PA5 GPIO/SPI1_SCK/ADC_IN5 General-purpose I/O or SPI1 clock
... ... ... ...

For a complete pinout, refer to the STM32F103 datasheet.

Usage Instructions

How to Use the STM32F103 in a Circuit

  1. Power Supply: Connect the VDD and VDDA pins to a stable power source (2.0V to 3.6V). Use decoupling capacitors (e.g., 0.1 µF) close to the power pins to reduce noise.
  2. Clock Configuration: The STM32F103 can use an external crystal oscillator or its internal RC oscillator. For precise timing, connect an external crystal (e.g., 8 MHz) to the OSC_IN and OSC_OUT pins.
  3. Reset Pin: Connect the NRST pin to a pull-up resistor (e.g., 10 kΩ) to ensure proper reset functionality.
  4. Programming: Use the SWD (Serial Wire Debug) interface for programming and debugging. Connect the SWDIO and SWCLK pins to a compatible programmer (e.g., ST-Link).
  5. Peripherals: Configure the GPIO pins and peripherals (e.g., USART, SPI, I2C) in the firmware using STM32CubeMX or direct register programming.

Important Considerations and Best Practices

Example: Interfacing STM32F103 with Arduino UNO

The STM32F103 can communicate with an Arduino UNO via UART. Below is an example of Arduino code to send data to the STM32F103:

Arduino Code

void setup() {
  Serial.begin(9600); // Initialize UART communication at 9600 baud
}

void loop() {
  Serial.println("Hello from Arduino!"); // Send data to STM32F103
  delay(1000); // Wait for 1 second
}

STM32F103 Code (Using HAL Library)

#include "stm32f1xx_hal.h"

UART_HandleTypeDef huart1; // UART handle for USART1

void SystemClock_Config(void);
void MX_USART1_UART_Init(void);

int main(void) {
  HAL_Init(); // Initialize the HAL library
  SystemClock_Config(); // Configure the system clock
  MX_USART1_UART_Init(); // Initialize USART1

  char rxData[50]; // Buffer to store received data

  while (1) {
    if (HAL_UART_Receive(&huart1, (uint8_t *)rxData, sizeof(rxData), 1000) == HAL_OK) {
      HAL_UART_Transmit(&huart1, (uint8_t *)rxData, strlen(rxData), 1000);
      // Echo received data back to the sender
    }
  }
}

void MX_USART1_UART_Init(void) {
  huart1.Instance = USART1;
  huart1.Init.BaudRate = 9600;
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  HAL_UART_Init(&huart1);
}

Troubleshooting and FAQs

Common Issues and Solutions

  1. Microcontroller Not Responding:

    • Ensure the power supply is stable and within the operating range (2.0V to 3.6V).
    • Check the reset pin (NRST) and ensure it is not held low.
  2. Programming Failure:

    • Verify the SWD connections (SWDIO, SWCLK) and ensure the programmer is properly connected.
    • Check the BOOT0 pin configuration. For Flash programming, BOOT0 should be set to 0.
  3. Peripheral Not Working:

    • Double-check the GPIO pin configuration in the firmware.
    • Ensure the clock for the peripheral is enabled in the RCC (Reset and Clock Control) register.
  4. High Power Consumption:

    • Use low-power modes (Sleep, Stop, Standby) when the microcontroller is idle.
    • Disable unused peripherals to reduce power consumption.

FAQs