yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
STM32-BoardCar📖
0. Get started quickly
  • 0.ReadMe
  • 1. Installation Instructions
  • 2. Version configuration
  • 3. Smart car installation video
  • 4. Precautions for use
1. Introduction to STM32 development board
  • 1. Learn about STM32
  • 2. Introduction to STM32 development board
  • 3. Development board pin assignment
  • 4. Introduction to HAL library and LL library
2. Setting up and using the development environment
  • 1. Common development tools
  • 2. STM32CubeMX Install - Use
  • 3. STM32CubeIDE Install - Use
  • 4. Common Driver Installation
  • 5. Program download and simulation
  • 6. Engineering experience and migration
3. Development board basic tutorial
  • 1. RGB searchlight (GPIO)
  • 2. Buzzer control (GPIO)
  • 3. Button control (EXTI)
  • 4. Serial communication (UASRT)
  • 5. Voltage detection (ADC)
  • 6. Internal temperature sensor(ADC)
  • 7. Independent watchdog(IWDG)
  • 8. Window watchdog(WWDG)
  • 9. Basic timer (TIM6)
  • 10. Universal Timer (TIM3)
  • 11. Advanced timers (TIM1)
  • 12. I2C Communication (IIC)
  • 13. Off-chip Flash (SPI)
  • 14. On-chip Flash (Flash)
  • 15. DMA:USART
  • 16. DMA:SPI
  • 17. DMA:I2C
  • 18. USB communication
  • 19. USB analog U disk
  • 20. FreeRTOS
4. Car expansion tutorial
  • 1. Servo control
  • 2. Basic use of ultrasonic steering gear gimbal
  • 3. Motor control
  • 4. OLED display light sensitivity value
  • 5. Infrared sensor
  • 6. Four-way tracking module
  • 7. Infrared remote control
  • 8. Ultrasonic ranging
  • 9. PS2 controller test
  • 10.K230 Vision Module
  • 11.AI voice interaction integration module
5. Robot car tutorials
  • 1. Car line patrol
  • 2. Ultrasonic follow
  • 3. Ultrasonic obstacle avoidance
  • 4. Ultrasonic obstacle avoidance (servo gimbal version)
  • 5. Infrared sensor obstacle avoidance
  • 6. Infrared remote control
  • 7. PS2 handle remote control
  • 8.K230 face tracking on PTZ
  • 9.K230 color tracking
  • 10.K230 Color Line Patrol
  • 11.K230 QR code command
  • 12.K230 machine code tracking
  • 13.K230 road sign indication action (voice)
  • 14.K230 color response (voice)
  • 15.K230 gesture control (voice)
  • 16.K230 Rock-Paper-Scissors Game (Voice)
6. Operation video
  • 1-How to install STM32CubeIDE software
  • 2-How to create Demo project
  • 3-How to download code into STM32 robot car
  • 4-How to open and compile a code file for STM32
  • 5-About IR control and Charge battery
Download
  • Code
  • SCH
  • Software File
  • STM32 Chip DataSheet
  • Installation manual
Download ZIP

Welcome to STM32-BoardCar repository

4. Serial communication (UASRT)

Serial communication

Serial communication1. Software-Hardware2. Brief principle1. Hardware schematic diagram2. Physical connection diagram3. Control principle3. Project configuration1. Description2. Pin configuration4. Main functions1. User function2. LL library function analysis5. Experimental phenomena

This tutorial demonstrates: sending and printing serial port information through serial port (USART1) interrupt.

1. Software-Hardware

  • STM32F103CubeIDE

  • STM32 Robot Development Board

    USART: chip internal peripherals

  • Type-C data cable or ST-Link

    Download programs or simulate the development board

2. Brief principle

1. Hardware schematic diagram

image-20231029181803977

2. Physical connection diagram

USART1 on the development board leads to two interfaces: Type-C and USART1;

It is recommended to use the Type-C burning interface for testing and sending and receiving serial port information.

image-20231029182815283

USART (schematic name)pinFunction
USART1_TXPA9USART1 sends data
USART1_RXPA10USART1 receives data

3. Control principle

Send data to the serial port (USART1) through the serial port debugging assistant to trigger the serial port interrupt, and print out the data through the serial port interrupt callback function.

  • Computer Communications

    Classified by data transmission method: serial communication and parallel communication

    • Serial Communication: Data is transferred bit by bit

image-20231029184915898

  • Parallel communication: Multiple bits of data are transmitted simultaneously

image-20231029184921894

  • Serial Communication

    • Serial communication data synchronization mode: synchronous serial communication and asynchronous serial communication

    Synchronous serial communication: The sender and receiver rely on independent clock lines to synchronize signals.

    Asynchronous serial communication: The sending and receiving parties complete communication according to the agreed character format and communication rate.

    image-20231029190935660

    • Serial communication data transmission direction: single duplex, half duplex and full duplex.

image-20231029185759888

Simplex: Data can only be transmitted in one direction, and cannot be sent and received at the same time;

Half-duplex: Data is transmitted in both directions, but cannot be sent and received at the same time;

Full Duplex: Data can be transmitted in both directions at the same time, and can be sent and received at the same time.

  • USART(Universal Synchronous/Asynchronous Receiver/Transmitter)

USART supports synchronous and asynchronous communication. Our tutorial uses UART (Universal Serial Asynchronous Receiver-Transmitter).

  • Asynchronous serial communication

    • Communication Rate

      Baud rate: The number of binary digits transmitted per second, in bit/s (bps).

Commonly used baud rates: 9600, 57600 and 115200
Baud rate 115200: 115200 bits transmitted per second
  • Character format

image-20231029191720269

xxxxxxxxxx
When transmitting data, the low bit comes first and the high bit comes last.

Data frame format: Start bit + data bit + check bit + stop bit

Start bit (beginning of data frame): 1 bit

Data bits: 5~8 bits

Check digit: odd or even parity (whether the number of "1"s in the data is odd or even)

Stop bit (end of data frame): 0.5, 1.5, 2 stop bits

image-20231029202215124

  • USART two-way communication
USART (development board)Peripheral/USB to TTL module
TXDRXD
RXDTXD
GNDGND
VCCVCC
Precautions1.TXD (transmitting line): pin used to transmit data
2.RXD (receiving line): pin used to receive data
3.GND (ground wire): used to connect to ground pins to ensure that the system level is consistent;
4.VCC (power line): If the peripherals do not have independent power supply, the VCC pin needs to be correctly connected to the appropriate power supply voltage;
5.USART two-way communication requires at least two pins: TXD (transmitting line) and RXD (receiving line).

Common serial port character format configuration: 1 start bit, 8 data bits, no parity, 1 stop bit

3. Project configuration

Project configuration: Prompt configuration options during STM32CubeIDE project configuration

1. Description

Omitted project configuration part: New project, chip selection, project configuration, SYS of pin configuration, RCC configuration, clock configuration and project configuration content

The project configuration part that is not omitted is the key point that needs to be configured in this tutorial.

xxxxxxxxxx
Please refer to [2. Development environment construction and use: STM32CubeIDE installation and use] to understand how to configure the omitted parts of the project.

2. Pin configuration

  • Configure specified pin function

You can directly select the corresponding pin number in the pin view, and the corresponding options will appear when you left-click the mouse.

image-20231029202409109

  • USART

image-20231029202911507

  • NVIC

Later, when it comes to modifying the interrupt priority, you need to enter the NVIC interface settings. The default priority is used here.

image-20231029203002449

  • Advanced Settings

image-20231029202755837

  • Generate code

image-20231011102854602

4. Main functions

It mainly introduces the functional code written by the user. For detailed code, you can open the project file provided by us yourself and enter the Bsp folder to view the source code.

1. User function

function:USART1_DataByte

function prototypevoid USART1_DataByte(uint8_t data_byte)
function descriptionSend a byte
Input parametersdata_byte:data
return valuenone

function:USART1_DataString

function prototypevoid USART1_DataString(uint8_t *data_str, uint16_t datasize)
function descriptionsend a string
Input parameters 1data_str: data first address
Input parameters 2datasize: Number of bytes of data
return valuenone

2. LL library function analysis

The HAL library functions that have been introduced in the previous tutorial will not be introduced again in the tutorial!

xxxxxxxxxx
If you want to find the HAL library and LL library function analysis involved in the entire tutorial, you can view the documents in the folder [8. STM32 Manual: STM32F1_HAL Library and LL Library_User Manual]

function: LL_USART_Init

function prototypeErrorStatus LL_USART_Init(USART_TypeDef *USARTx, const LL_USART_InitTypeDef *USART_InitStruct)
function descriptionInitialize USART peripheral
Input parameters 1USARTx:USARTx handle address
Input parameters 2USART_InitStruct: USART initialization structure, containing configuration information of the specified USART peripherals
return valueErrorStatus:SUCCESS、ERROR

function:LL_USART_ConfigAsyncMode

function prototypevoid LL_USART_ConfigAsyncMode(USART_TypeDef *USARTx)
function descriptionConfigure the specified USART peripheral to asynchronous mode
Input parametersUSARTx:USARTx handle address
return valuenone

function:LL_USART_Enable

function prototypevoid LL_USART_Enable(USART_TypeDef *USARTx)
function descriptionEnable specified USART peripheral
Input parametersUSARTx:USARTx handle address
return valuenone

function:LL_USART_ReceiveData8

function prototypeuint8_t LL_USART_ReceiveData8(const USART_TypeDef *USARTx)
function descriptionSpecify the USART peripheral to receive 8-bit data
Input parametersUSARTx:USARTx handle address
return valuereceived data

function:LL_USART_TransmitData8

function prototypevoid LL_USART_TransmitData8(USART_TypeDef *USARTx, uint8_t Value)
function descriptionSpecify the USART peripheral to send 8-bit data
Input parameters 1USARTx:USARTx handle address
Input parameters 2Value: sent data
return valuenone

function:LL_USART_IsActiveFlag_TXE

function prototypeuint32_t LL_USART_IsActiveFlag_TXE(const USART_TypeDef *USARTx)
function descriptionCheck the TXE flag status of the specified USART peripheral
Input parametersUSARTx:USARTx handle address
return value0 (inactive), 1 (active)

function:LL_USART_EnableIT_RXNE

function prototypevoid LL_USART_EnableIT_RXNE(USART_TypeDef *USARTx)
function descriptionEnable specified USART peripheral receive interrupt
Input parametersUSARTx:USARTx handle address
return valuenone

function:LL_USART_IsEnabledIT_RXNE

function prototypeuint32_t LL_USART_IsEnabledIT_RXNE(const USART_TypeDef *USARTx)
function descriptionCheck whether the receive data register non-empty interrupt of the specified USART peripheral is enabled
Input parametersUSARTx:USARTx handle address
return value0 (disabled), 1 (enabled)

5. Experimental phenomena

After successfully downloading the program, press the RESET button on the development board to open the serial port debugging assistant to observe the phenomenon!

xxxxxxxxxx
For program download, please refer to [2. Development environment construction and use: program download and simulation]

Phenomenon:

Use the serial port debugging assistant to send information, and you can see that the serial port returns the same information.

image-20231102182541744

Button control (EXTI)
Voltage detection (ADC)

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文