STM32 Serial Port – UART With USB-TTL Converter | PC Interfacing

Previous Tutorial Previous Tutorial Tutorial 11 Next Tutorial Next Tutorial
STM32 Serial Port Interfacing With PC
STM32 Course Home Page ????

 

STM32 Serial Port PC Interfacing USB-TTL UART Send Receive

 

In this LAB, we’ll be doing PC interfacing via the serial port using the USB-TTL converter and UART module in the STM32F103C8 microcontroller (Blue Pill Board). We’ll send and receive asynchronous UART data from and to the PC. So, Let’s get started!

[toc]


   Required Components For LABs   

 

All the example code/LABs/projects in the course are going to be done using those boards below.

QTY Component Name ???? Amazon.com ???? eBay.com
2 BreadBoard Amazon eBay
1 LEDs Kit Amazon Amazon eBay
1 Resistors Kit Amazon Amazon eBay
1 Capacitors Kit Amazon Amazon eBay & eBay
2 Jumper Wires Pack Amazon Amazon eBay & eBay
1 9v Battery or DC Power Supply Amazon Amazon Amazon eBay
1 Micro USB Cable Amazon eBay
1 Push Buttons Amazon Amazon eBay
1 USB-TTL Converter or FTDI Chip Amazon Amazon eBay  eBay

★ Check The Full Course Complete Kit List

Some Extremely Useful Test Equipment For Troubleshooting:

Affiliate Disclosure: When you click on links in this section and make a purchase, this can result in this site earning a commission. Affiliate programs and affiliations include, but are not limited to, the eBay Partner Network (EPN) and Amazon.com.


   Preface & LAB Objectives   

 

LAB Number 6
LAB Title Serial Port Read/Write With Blue Pill + USB-TTL Converter
  • Configure GPIO input pin (for push-button) & output pins (for LEDs)
  • Configure UART in asynchronous mode @ 9600 bps + Enable RX interrupts
  • Read the button state and send it to the PC via serial port
  • Read the received characters from the PC and decide which led is to be toggled

 


   STM32 Serial Port Interfacing LAB   

 

Preface

The Blue Pill development board lacks an onboard ST-Link programmer/debugger, unlike Nucleo boards. That’s why we use the external USB ST-Link clone. And also it worth mentioning that the USB port on the blue pill board is connected to the STM32F103C8 hardware USB peripheral. Therefore, it can actually be used for debugging but you’ll develop a USB application for it and it’s a topic for a future tutorial.

However, the UART peripherals in the microcontroller can be used to send serial data to the PC serial COM port and display it on a terminal using a USB-TTL converter board. Hence, you’re not restricted to use a specific UART module (UART1, UART2, or UART3).

Note

The STM32F103C8 microcontrollers’ pins are not all 5v tolerant. Hence, you must be careful when receiving input signals from the USB-TTL converter. You can send a 3.3v signal from the MCU TX pin to the USB-TTL RX pin and still get the data identified absolutely fine. However, it won’t work the other way around without shifting the signal’s level. The TX from the USB-TTL can over-drive the MCU’s RX input pin. By checking the diagram below, you’ll notice that the pins for UART1 & UART3 are 5v tolerant while UART2 is not.

stm32f103c8t6_pinout_voltage01

 

LAB Connection Diagram

STM32 Serial Port USB-TTL PC Interfacing UART Send Receive Example

 

LAB Project Code (Step-By-Step)

 

Step1: Open CubeMX & Create New Project

Step2: Choose The Target MCU & Double-Click Its Name

STM32 CubeMX Choose The Part Step

Step3: Enable USART1 Module (Asynchronous Mode)

STM32 Nucleo Serial Port Print To PC Terminal1

Step4: Choose The Desired Settings For UART (Baud Rate, Stop Bits, Parity, etc..)

STM32 Debugging Nucleo Serial Port Print To PC Terminal1

  • Set the baud rate to 9600 bps
  • Enable UART global interrupts in NVIC tab

Step5: Configure The Required GPIO Pins For This Project

  • PB12, PB13: Output Pins (For LEDs)
  • PB14: Input Pin (For The Push Button)

Step6: Goto The RCC Options Tab & Enable External Crystal

How To Use STM32 Nucleo32 Serial Port UART 1

Step7: Go To The Clock Configuration & Set The System Clock To 72MHz

STM32 Clock Tree Configuration CubeMX

Step8: Generate The Initialization Code & Open The Project In CubeIDE

Step9: Write The Application Layer Code For This LAB

Step10: Build & Debug To Flash The Code

Step11: Go To The Device Manager & Check The USB-TTL COM Port Num.

STM32 Serial Port PC Communication USB-TTL

Step12: Open The Terminal From CubeIDE or Any Other Terminal

Window > Show View > Console

In Console: click on the NEW icon on its menu bar > Command Shell console > Connection type: Serial port > set Baud Rate & Connection Name > Encoding: UTF-8 > And Click OK!

Alternatively, You Can Use Any Terminal On Your PC (Like Tera Term, Arduino Serial Monitor, etc..)

 

Download The Project Folder

 


 

 

Don’t Forget To Support The Content By SHARING It On Socials Or Via Patreon!

 

 

Previous Tutorial Previous Tutorial Tutorial 11 Next Tutorial Next Tutorial

 

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Author
Khaled Magdy
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?

2 thoughts on “STM32 Serial Port – UART With USB-TTL Converter | PC Interfacing”

Leave a Comment