K210 module-Serial communication (USART)

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

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

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.

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.

Control function

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

USART2_init

USART2_Send_U8

USART2_Send_ArrayU8

USART2_IRQHandler

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.

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