Welcome to K210 Module repository
9. MSPM0_K210 Object Detection
MSPM0_K210 Object Detection
1. K210 and MSPM0 Communication
1.1 Experimental Prerequisites
This tutorial uses the MSPM0G3519 development board. K210 needs to run the program in K210-AI(MSPM0) to start the experiment.
MSPM0G3519 *1
K210 vision module *1 (with SD card (with AI model) and camera)
USB to TTL module *1
1.2 Experimental Wiring
Method 1: Using USB to TTL module
| MSPM0G | K210 Vision Module |
|---|---|
| RX | TXD |
| GND | GND |
| VCC | 5V |
| MSPM0G | USB to TTL Module |
|---|---|
| TX | RXD |
| GND | GND |

Method 2: Using onboard Type-C port

1.3 Main Code Explanation
This example sets the serial port print baud rate to 115200 bps, and the K210 module connection baud rate is set to 115200 bps.


xint main(void){SYSCFG_DL_init();NVIC_ClearPendingIRQ(MYUART_INST_INT_IRQN);//Clear serial port interrupt flagNVIC_EnableIRQ(MYUART_INST_INT_IRQN);//Enable serial port interruptwhile (1){if (k210_msg.class_n != 0)//Example number is not empty{if(k210_msg.class_n == 9)//Object detection{sprintf(buff_com,"x=%d,y=%d,w=%d,h=%d\r\n",k210_msg.x,k210_msg.y,k210_msg.w,k210_msg.h);uart0_send_string(buff_com);sprintf(buff_com,"id = %s\r\n",k210_msg.msg_msg);uart0_send_string(buff_com);k210_msg.class_n = 0;//Clear example number}}delay_ms(500);}}
After the above program runs this example, the k210_msg structure members will have corresponding values and will be printed via serial port.
k210_msg: is the structure for receiving information. Its main members are:
x: is the x-coordinate of the upper-left corner of the recognized box (range: 0-240)
y: is the y-coordinate of the upper-left corner of the recognized box (range: 0-320)
w: is the width of the recognized box (range: 0-240)
h: is the height of the recognized box (range: 0-320)
id: is the recognized label
class_n: example number
msg_msg[20]: valid data
After data reception and processing, each member of k210_msg will store valid information. If you want to do secondary development, you can directly call the members of k210_msg.
Note: The Keil project source code must be placed under the SDK path for compilation.
1.4 Experimental Phenomenon
After connecting the cables, the K210 vision module runs offline K210 offline running method
Set the serial assistant interface as shown in the figure

Then run the object detection example. The serial assistant will print the important information transmitted by K210 to MSPM0G, as shown in the figure below.

Object detection only transmits the 6 member variables of k210_msg: x, y, w, h, id, msg.
id: The information content is (0.airplane, 1.bicycle, 2.bird, 3.boat, 4.bottle, 5.bus, 6.car, 7.cat, 8.chair, 9.cow, 10.dining table, 11.dog, 12.horse, 13.motorcycle, 14.person, 15.potted plant, 16.sheep, 17.sofa, 18.train, 19.monitor)