K210(K210)

The K210 module is a marginal computing device that optimizes the ability of image processing.

Global variable

Global variabletypeAnnotation
buf_msgchar[20]K210 Receive message buffer
g_new_flaguint8_tReceive flag, used to indicate whether the new message is being received
g_indexuint8_tMessage index, used to store the receiving characters

Macro definition

Macro definitionro definitionvalueAnnotation
BUFFER_SIZE40K210 Receive buffer size

method

USART2_init(u32 baudrate)

Initialize USART2 (for K210 communication)

parametertypeAnnotation
baudrateu32Baud rate
Return valuetype
nonevoid

K210_Deal_Recv(uint8_t recv_msg)

Analyze the message from the K210 module

parametertypeAnnotation
recv_msguint8_tReceived characters
Return valuetype
Return to the complete string receivedchar*
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

parametertypeAnnotation
data_strconst char*String to be sent
Return valuetype
nonevoid

USART2_Send_U8(uint8_t ch)

Send a character to the K210 module

parametertypeAnnotation
chuint8_tThe characters to be sent
Return valuetype
nonevoid

USART2_Send_ArrayU8(uint8_t *BufferPtr, uint16_t Length)

Send a byte array to the K210 module

parametertypeAnnotation
BufferPtruint8_t*Data pointer to be sent
Lengthuint16_tData length
Return valuetype
nonevoid

USART2_IRQHandler(void)

USART2 interrupt service function, process the received data

Return valuetype
nonevoid

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 fm

fm.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);
        }
    }
}