Welcome to STM32-BoardCar repository
10.K230 Vision Module
k230 visual recognition module
k230 visual recognition module1. Software-Hardware2. Brief Principle1. Hardware Schematic2. Physical connection diagram3. Control Principle3. Project configuration1. Description2. Pin configuration4. Main functions1. User function5. Experimental phenomenon
This tutorial demonstrates: how to use the STM32 expansion board with the k230 visual recognition module and how to control the k230 module using the function keys on the expansion board.
1. Software-Hardware
STM32F103CubeIDE
STM32 Robot Development Board
Function keys integrated on the development board
k230 visual module
Type-C data cable or ST-Link
Download or simulate the development board
Serial Port Assistant
Receive serial port data and print
2. Brief Principle
1. Hardware Schematic

2. Physical connection diagram

3. Control Principle
| (Schematic Name) | Control pin | Specific meaning |
|---|---|---|
| USART2_RX | PD6 | Transmitter |
| USART2_TX | PD5 | Receiver |
Serial communication:
USART: Universal synchronous asynchronous receiver and transmitter. It is a hardware peripheral integrated in STM32. It can automatically generate data frame timing according to a byte of data in the data register and send it out from the TX pin. It can also automatically receive the data frame timing of the RX pin and splice it into a byte of data and store it in the data register. **
STM32F103ZET6 has 3 USARTs and 2 UARTs. USART2 is used in this experiment.
When using the serial port for communication, the two communicating parties must be "same channel". "Same channel" refers to the same communication protocol. Serial port (USART) agreement: data must be transmitted in the form of "frames" during communication. A frame of serial port data includes: start bit + data bit + check bit + stop bit Among them:
Start bit: fixed to a low-level signal of 1 cycle
Data bit: can be agreed upon by both parties to the communication to be 5 ~ 9 bits
Check bit: The serial port uses parity check, which can be agreed upon by both parties to the communication
Stop bit: optional 0.5 ~ 2 cycles of high level At the same time, in order to synchronize the sending and receiving speed of the two-way communication, it is also necessary to agree on the number of data frames transmitted per second, which is called baud rate. Typical baud rates are 9600, 115200, 57600...
The functions of the k230 visual module are distributed as follows:
In order to compress the module volume, our K230 module does not lead out all the pins supported by the chip. Let's take a look at some commonly used pins of YAHBOOM K230
Two rows of pins next to the heat sink

1: GPIO 42, can be reused as: GPIO42 / UART1_RTS / PWM0 / QSPI1_D2 / RESV /
2: GPIO 43, can be reused as: GPIO43 / UART1_CTS / PWM1 / QSPI1_D3 / RESV /
3: GPIO 33, can be reused as: GPIO33 / IIC0_SDA / IIS_WS / UART3_RXD / RESV /
4: GND
5: GPIO 32, can be reused as: GPIO32 / IIC0_SCL / IIS_CLK / UART3_TXD / RESV /
6: GPIO 26, can be reused as: GPIO26 / MMC1_CLK / RESV / PDM_CLK /
7: GND
8: GPIO 34, can be reused as: GPIO34 / IIC1_SCL / IIS_D_IN0 / PDM_IN3 / UART3_RTS /
9: 5v output
10: GPIO 35, can be reused as: GPIO35 / IIC1_SDA / IIS_D_OUT0 / PDM_IN1 / UART3_CTS /
11: 5v output
12: 3.3v output
! ! ! When connecting the 12pin GPIO, please be sure to confirm the silkscreen mark to ensure the correct connection. After-sales repair service will not be provided for man-made damage caused by short circuit, reverse connection, overvoltage or overcurrent. ! ! ! !
The operation process is as follows:
3. Project configuration
1. Description
Omitted project configuration part: New project, chip selection, project configuration, pin configuration SYS, RCC configuration, clock configuration and project configuration content
xxxxxxxxxxPlease refer to [2. Development environment construction and use: STM32CubeIDE installation-use] to understand how the omitted part of the project is configured
2. Pin configuration





4. Main functions
According to our tutorial, STM32CubeIDE can generate the corresponding gpio.c, gpio.h, tim.c and tim.h files. For the later transplantation and peripheral module driver, we will place the automatically generated code in the BSP folder under the project file.
1. User function
Function: Send_k230
| Function prototype | void Send_k230(uint8_t *data_str, uint16_t datasize) |
|---|---|
| Function description | Control the status of the RGB light on k230 |
| Input parameter 1 | Data |
| Input parameter 2 | Data length |
| Output parameter | None |
Function: Deal_k230
| Function prototype | void Deal_k230(uint8_t recv_msg) |
|---|---|
| Function description | Retain information of k230 |
| Input parameter | Information sent by the serial port |
| Output parameter | None |
Function: Change_RGB
| Function prototype | void Change_RGB(void) |
|---|---|
| Function description | Change the onboard RGB status |
| Input parameters | None |
| Output parameters | None |
Communication protocol:
k230 part:
Receiving part: When receiving MCU data from the serial port, parse it, and then the RGB light will give corresponding color feedback.
Sending part: k230 will send the color data through the serial port again, the format is "$"+color name+"#".
MCU part:
Sending part: When the expansion board button is pressed, the color data will be sent to k230 through the serial port.
Receiving part: Receive the data sent by k230 through the serial port and process each bit of the data.
Determine the data frame: If it is "$", the flag position is 1, and then the string array is initialized; then process the next bit of data, if it is not "#", the content is stored in the data. Until "#" is recognized, the flag position is 0, and then the array data is processed. When the array content is compared to the specific content, the RGB light on the car expansion board will give the corresponding color feedback.
5. Experimental phenomenon
After downloading the program, we connect the k230 and the expansion board. Then we control the RGB light of k230 through the function keys on the expansion board.
When we press the key1 button, the RGB light of k230 will light up a color. Press the key1 key once, and it will light up a color;
When we press the key2 button, the RGB light of k230 will light up the other three colors (three different colors from pressing the key1 key), and press the key2 key once, and it will light up a color;
When we press the key3 button, the RGB light of k230 will turn off.
The RGB light of the car will be synchronized with the state of k230.
xxxxxxxxxxFor program download, please refer to [2. Development environment construction and use: program download and simulation]
How to download k230 code:
Required tools: K230, SD card, CanMV IDE K230
We find the K230uart_car.py file in the project folder, then drag it to CanMV IDE K230, and then choose to save the opened script as main.py to CanMV
