Bootstrap

K210 串口通讯

Canmv K210

首先是其引脚的的定义:

在对其串口初始化 :

对其串口测试:

 

其中printf是打印在串行终端

uart_A.write是进行串口通信的,打开串口助手即可接收信息

总代码: 

from fpioa_manager import fm
from machine import UART
from machine import Timer
import time

# 引脚配置
fm.register(7, fm.fpioa.UART1_TX, force=True)
fm.register(6, fm.fpioa.UART1_RX, force=True)

# 初始化UART1
uart_A = UART(UART.UART1, 115200, 8, 0, 0, timeout=1000, read_buf_len=4096)

# 测试串口收发
write_bytes = b'hello world\r\n'
uart_A.write(write_bytes)
time.sleep_ms(1)
while True:
    if uart_A.any():
        read_data = uart_A.read()
        if read_data:
            print("write_bytes = ", write_bytes)
            print("read_data = ", read_data)
            uart_A.write(read_data)
            if read_data == write_bytes:
                print("baudrate:115200 bits:8 parity:0 stop:0 ---check Successfully")

uart_A.deinit()
del uart_A
;