yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
Self-balancing Robot Car📖
00.Get started quickly
  • 01.Balance car manual
  • 02.Balancing car assembly
  • 03.Get started quickly
  • 04.Balance car interface description
  • 05.Common Problem Analysis
  • 06.Balance Car V2 Library Function Development Manual
01.Environment development
  • 01.MDK-ARM installation
  • 02.STM32CubeIDE installation
  • 03.Common driver installation
  • 04.Download the program
  • 05.MDK-ARM project usage
  • 06.Program simulation
  • 07. VSCode Installation
02.STM32 getting started course
  • 01.Project creation
  • 02.LED Control(GPIO)
  • 03.Buzzer control(GPIO)
  • 04.Button control(EXTI)
  • 05.Serial communication(USART)
  • 06.Voltage detection(ADC)
  • 07.Basic timer(TIM)
  • 08.Universal timer(TIM)
  • 09.Advanced Timer(TIM)
  • 10.I2C Communication(I2C)-OLED
  • 11.SPI communication(SPI)-2.4G handle
  • 12.Independent Watchdog (IWDG)
  • 13.Window Watchdog (WWDG)
  • 14.DMA-USART
  • 15.DMA-I2C
03.STM32 expansion course
  • 01.Battery voltage detection (ADC)
  • 02.Ultrasonic module-measuring distance (TIM)
  • 03.Motor drive+encoder (TIM)
  • 04.OLED Data-Display(I2C)
  • 05.MPU6050-Data Read (I2C)
  • 06.Bluetooth module-Data reading (USART)
  • 07.2.4G handle-Data reading (SPI)
  • 08.Tracking module-Read status (GPIO)
  • 09.CCD module-Reading data (ADC)
  • 10.Electromagnetic module-Reading data (ADC)
  • 11.K210 module-Serial communication (USART)
  • 12.Tmini-Plus lidar-Reading data (USART)
04.Robot car PID control course
  • 01.PID basic concept
  • 02.PID example analysis
  • 03.P, PI, PD controller theory
  • 04.Position PID
  • 05.Incremental PID
  • 06.Cascade PID
  • 07.Balance principle of car
  • 08.Car upright control (PD)
  • 09.Car speed ​​control (PI)
  • 10.Car steering control (PD)
  • 11.Got angle and angular velocity (DMP algorithm)
  • 12.Got angle and angular velocity (Kalman filter algorithm)
  • 13.Got angle and angular velocity(Complementary filter algorithm)
05.Robot car basic course
  • 01.Car parameter adjustment
  • 02.Ultrasonic obstacle avoidance
  • 03.Ultrasonic follow
  • 04.Bluetooth remote control
  • 05.Load balance
06.Robot car advanced course
  • 01.4-channel tracking
  • 02.4-channel tracking avoid
  • 03.2.4G handle control
  • 04.CCD tracking
  • 05.CCD tracking avoid
  • 06.Electromagnetic tracking
  • 07.K210-QR code recognition
  • 08.K210-Color line tracking
  • 09.K210-Color follow
  • 10.K210-Self learning
  • 11.K210-Number recognition
  • 12.Lidar avoid
  • 13.Lidar guard
  • 14.Lidar follow
  • 15.Lidar patrol
  • 16.Lidar wall tracking-straight line
  • 17.Lidar wall tracking-multiple walls
  • 18. DIY Automatic driving car
07.Robot car LQR control
  • Robot car LQR control
08.Circuit design
  • 01.Overall circuit design
  • 02.STM32 minimum system
  • 03.Serial port circuit design
  • 04.Power circuit design
  • 05.MPU6050 Circuit Design
  • 06.Motor drive circuit design
09.Mathematical model
  • Mathematical model
10.Expand course
  • Autonomous Driving
Download
  • APP(Android)
  • Codes
  • Hardware-Info
  • SCH
  • Software Tools
  • STM32_Chip_DataSheet
  • 3D_Model_File
  • Video_PPT
Download ZIP

Welcome to Self-balancing Robot Car repository

11.K210 module-Serial communication (USART)

K210 module-Serial communication (USART)

K210 module-Serial communication (USART)Hardware connectionControl principleSoftware configurationPin definitionSoftware codeControl functionExperimental phenomenon

The tutorial controls the RGB light color of the K210 visual module through buttons.

The tutorial only introduces the standard library project code

Hardware connection

image-20240825214808338

Since we have configured a special connection line, we only need to install it to the corresponding interface:

PeripheralsDevelopment board
K210 visual module: VCC5V
K210 visual module: TXDPA2
K210 visual module: RXDPA3
K210 visual module: GNDGND

Control principle

  • K210 visual module

The K210 visual module itself is a development board. For detailed use, please refer to the module supporting tutorial.

image-20240808163347296

Download program

Connect the SD card of the K210 visual module to the computer through a card reader, rename the program file to main.py and copy it to the SD card, then reinstall the SD card into the SD card slot of the K210 visual module.

xxxxxxxxxx
The K210 visual module and development board case codes are in the same folder: the folder name will distinguish the development board to which the code belongs

Communication protocol

The development board program controls serial port 2 to send different data through the onboard KEY button;

The K210 visual module program will parse the data sent by the development board serial port 2 and control the color of the RGB light on the K210 visual module board according to the data.

Number of key pressesContent sent by serial port 2K210 visual module RGB light status
0$blue#Blue
1$red#Red
2$green#Green
3$yellow#Yellow
4$purper#Purple
5$lake#Cyan
6$close#Close

Software configuration

Pin definition

Main control chipPinMain function (after reset)Default multiplexing functionRedefine function
STM32F103RCT6PA2PA2USART2_RTS/ADC123_IN1/TIM5_CH2/TIM2_CH2 
STM32F103RCT6PA3PA3USART2_TX/TIM5_CH3 ADC123_IN2/TIM2_CH3 

Software code

Since the default pin function is the normal IO pin function, we need to use the default multiplexing function.

xxxxxxxxxx
Product supporting materials source code path: Attachment → Source code summary → 2.Extended_Course → 11.k210

Control function

The tutorial only briefly introduces the code, you can open the project source code to read it in detail.

USART2_init

​x
void USART2_init(u32 baudrate)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;
    NVIC_InitTypeDef NVIC_InitStructure; 
    
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
    
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);    

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    
    NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
      
    USART_InitStructure.USART_BaudRate = baudrate;
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
    USART_InitStructure.USART_Parity = USART_Parity_No ;
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
    USART_Init(USART2, &USART_InitStructure); 
 
    USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);        
    //USART_ClearFlag(USART2,USART_FLAG_TC);
    USART_Cmd(USART2, ENABLE);
}

USART2_Send_U8

xxxxxxxxxx
void USART2_Send_U8(uint8_t ch)
{
    while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)
        ;
    USART_SendData(USART2, ch);
}

USART2_Send_ArrayU8

xxxxxxxxxx
void USART2_Send_ArrayU8(uint8_t *BufferPtr, uint16_t Length)
{
    while (Length--)
    {
        USART2_Send_U8(*BufferPtr);
        BufferPtr++;
    }
}

USART2_IRQHandler

xxxxxxxxxx
void USART2_IRQHandler(void)
{
    uint8_t Rx2_Temp;
    if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
    {
        USART_ClearITPendingBit(USART2, USART_IT_RXNE);
        Rx2_Temp = USART_ReceiveData(USART2);
        
        Deal_K210(Rx2_Temp);
    }
}

Experimental phenomenon

The K210.hex file generated by the project compilation is located in the OBJ folder of the K210 project. Find the K210.hex file corresponding to the project and use the FlyMcu software to download the program to the development board.

xxxxxxxxxx
The corresponding functions can only be realized when both the K210 visual module and the development board have downloaded the program

After the program is successfully downloaded: press the KEY button to switch the RGB light color of the K210 visual module.

Electromagnetic module-Reading data (ADC)
Tmini-Plus lidar-Reading data (USART)

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/中文