STM32 Blue Pill Serial UART Echo: Wiring, Code and Simulator
To build this STM32 Blue Pill Serial UART Echo project you need an STM32 Blue Pill (STM32F103C8) and nothing but the board itself. Serial on USART1 receives what you type: the Blue Pill answers each line in capitals and toggles its PC13 LED. Make the 0 connections in the wiring table, upload the Arduino C++ code, and type a word into the serial monitor and press Enter. The reply comes back in capitals.
Open this circuit in the free STM32 Blue Pill (STM32F103C8) simulator
Parts list
| Qty | Part | What it does |
|---|---|---|
| 1 | STM32 Blue Pill (STM32F103C8) | the microcontroller board |
Wiring
No wiring: this project uses only the STM32 Blue Pill (STM32F103C8).
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the STM32 Blue Pill (STM32F103C8). No install or account is needed.
- Add the parts. Add nothing but the board itself from the parts palette.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- Run it. Press Run. Type a word into the serial monitor and press Enter. The reply comes back in capitals.
Arduino C++ code
// Type into the serial monitor: the Blue Pill answers each line in capitals
// and toggles its LED (PC13) for every line it receives.
String line;
void setup() {
Serial.begin(115200);
pinMode(PC13, OUTPUT);
digitalWrite(PC13, HIGH); // off
Serial.println("Type something and press Enter");
}
void loop() {
while (Serial.available()) {
char c = Serial.read();
if (c == '\n' || c == '\r') {
if (line.length()) {
line.toUpperCase();
Serial.print("You said: ");
Serial.println(line);
digitalWrite(PC13, !digitalRead(PC13));
line = "";
}
} else {
line += c;
}
}
}
What to try
Type a word into the serial monitor and press Enter. The reply comes back in capitals.
Frequently asked questions
How do I wire the Serial UART Echo project on an STM32 Blue Pill (STM32F103C8)?
No extra wiring is needed: it uses only the STM32 Blue Pill (STM32F103C8) itself.
What parts do I need for this STM32 Blue Pill project?
An STM32 Blue Pill (STM32F103C8) and nothing but the board itself.
Can I simulate this STM32 Blue Pill project online for free?
Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is built with the STM32duino core and runs on an STM32F103 emulated instruction by instruction: its ARM Cortex-M3 core, NVIC and peripherals (GPIO, EXTI, USART, timers, ADC and I²C).
What does the code do?
Serial on USART1 receives what you type: the Blue Pill answers each line in capitals and toggles its PC13 LED.
More STM32 Blue Pill (STM32F103C8) projects
- STM32 Blue Pill HC-05 Bluetooth on USART2: Wiring, Code and Simulator
- STM32 Blue Pill LED Blink and Serial: Wiring, Code and Simulator
- STM32 Blue Pill Button Interrupt (EXTI): Wiring, Code and Simulator
- STM32 Blue Pill ADC Potentiometer and PWM LED: Wiring, Code and Simulator
- STM32 Blue Pill I2C BMP280 with Wire: Wiring, Code and Simulator
- STM32 Blue Pill Servo Motor Sweep: Wiring, Code and Simulator