K210(K210)
The K210 module is a marginal computing device that optimizes the ability of image processing.
Global variable
| Global variable | type | Annotation |
|---|---|---|
| buf_msg | char[20] | K210 Receive message buffer |
| g_new_flag | uint8_t | Receive flag, used to indicate whether the new message is being received |
| g_index | uint8_t | Message index, used to store the receiving characters |
Macro definition
| Macro definitionro definition | value | Annotation |
|---|---|---|
| BUFFER_SIZE | 40 | K210 Receive buffer size |
method
USART2_init(u32 baudrate)
Initialize USART2 (for K210 communication)
| parameter | type | Annotation |
|---|---|---|
| baudrate | u32 | Baud rate |
| Return value | type |
|---|---|
| none | void |
K210_Deal_Recv(uint8_t recv_msg)
Analyze the message from the K210 module
| parameter | type | Annotation |
|---|---|---|
| recv_msg | uint8_t | Received characters |
| Return value | type |
|---|---|
| Return to the complete string received | char* |
| By default, the '$' character is used as the data packet head, and the '#' is used as the data packet tail | |
K210_Send_Msg(const char *data_str)
Send a string message to the K210 module
| parameter | type | Annotation |
|---|---|---|
| data_str | const char* | String to be sent |
| Return value | type |
|---|---|
| none | void |
USART2_Send_U8(uint8_t ch)
Send a character to the K210 module
| parameter | type | Annotation |
|---|---|---|
| ch | uint8_t | The characters to be sent |
| Return value | type |
|---|---|
| none | void |
USART2_Send_ArrayU8(uint8_t *BufferPtr, uint16_t Length)
Send a byte array to the K210 module
| parameter | type | Annotation |
|---|---|---|
| BufferPtr | uint8_t* | Data pointer to be sent |
| Length | uint16_t | Data length |
| Return value | type |
|---|---|
| none | void |
USART2_IRQHandler(void)
USART2 interrupt service function, process the received data
| Return value | type |
|---|---|
| none | void |
Example
K210 code, please refer to the tutorial to run the following code on the K210 visual module
from machine import UART
from fpioa_manager import fmfm.register(8, fm.fpioa.UART1_TX, force=True)
fm.register(6, fm.fpioa.UART1_RX, force=True)
uart_A = UART(UART.UART1, 115200, 8, 0, 1, timeout=1000, read_buf_len=4096)
uart_A.write(”$Hello Yahboom#”)
Self-balancing Robot code
#include "bsp_usart2.h"
#include "bsp_k210.h"
int main() {
bsp_init();
while(1) {}
return 0;
}
// Serial interrupt service function
// !Notice!
// USART2_IRQHANDLER () function is written in the BSP_USART2.C file by default
// If you want to deal with this interrupt in main.c, you need to delete the USART2_IRQHANDLER () function in bsp_usart2.c
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);
char* res;
res = K210_Deal_Recv(Rx2_Temp);
if(res != NULL) {
printf("recv: %s\n" , res);
}
}
}