当前位置:网站首页>K210 serial communication

K210 serial communication

2022-04-23 18:33:00 Scroll monster

One 、 Serial port configuration

from machine import UART    # Import UART modular 
fm.register(9, fm.fpioa.UART1_TX, force=True) #9 by tx Pick up rx
fm.register(10, fm.fpioa.UART1_RX, force=True) #10 by rx Pick up tx
uart_A = UART(UART.UART1, 9600, 8, 1, 0, timeout=1000, read_buf_len=4096)

Basically, it is to configure the pin of serial port and the setting of serial port parameters .

Two 、 Serial port sends data

Serial port sends data call uart_A.write() that will do .

3、 ... and 、 Serial port receives data

Serial port receiving data call uart_A.read() that will do . Pay attention to mxai py Byte stream data received in , You need to convert bytes into strings and remove the terminator to use the received data ( If it is necessary to use data to judge )

if uart_A.any():
    while uart_A.any():
        read_data = uart_A.read()
        read_data = read_data.decode('utf-8','ignore')  #  To string 
            if read_data[0] == 'b':                     #  section 
               .....
               read_data = ''

版权声明
本文为[Scroll monster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231826029023.html