# test we can correctly create by id or name for bus in (-1, 0, 1, 2, 3, 4, 5, 6, 7, "Z"): try: UART(bus, 9600) print("UART", bus) except ValueError: print("ValueError", bus) uart = UART(1) uart = UART(1, 9600) uart = UART(1, 9600, bits=8, parity=None, stop=1) print(uart) uart.init(2400) print(uart) print(uart.any()) print(uart.write('123')) print(uart.write(b'abcd')) print(uart.writechar(1)) # make sure this method exists uart.sendbreak() # non-blocking mode uart = UART(1, 9600, timeout=0) print(uart.write(b'1')) print(uart.write(b'abcd')) print(uart.writechar(1)) print(uart.read(100))
from pyb import UART uart = UART(1) uart = UART(1, 9600) uart = UART(1, 9600, bits=8, parity=None, stop=1) print(uart) uart.init(2400) print(uart) print(uart.any()) print(uart.write('123')) print(uart.write(b'abcd')) print(uart.writechar(1)) # make sure this method exists uart.sendbreak()
uart_id_range = range(0, 2) uart_pins = [[('GP12', 'GP13'), ('GP12', 'GP13', 'GP7', 'GP6')], [('GP16', 'GP17'), ('GP16', 'GP17', 'GP7', 'GP6')]] else: raise Exception('Board not supported!') # just in case we have stdio duplicated on any of the uarts pyb.repl_uart(None) for uart_id in uart_id_range: uart = UART(uart_id, 38400) print(uart) uart.init(57600, 8, None, 1, pins=uart_pins[uart_id][0]) uart.init(baudrate=9600, stop=2, parity=UART.EVEN, pins=uart_pins[uart_id][1]) uart.init(baudrate=115200, parity=UART.ODD, stop=0, pins=uart_pins[uart_id][0]) uart = UART(baudrate=1000000) uart.sendbreak() uart = UART(baudrate=1000000) uart = UART() print(uart) uart = UART(baudrate=38400, pins=('GP12', 'GP13')) print(uart) uart = UART(pins=('GP12', 'GP13')) print(uart) uart = UART(pins=(None, 'GP17')) print(uart) uart = UART(baudrate=57600, pins=('GP16', 'GP17')) print(uart) # now it's time for some loopback tests between the uarts uart0 = UART(0, 1000000, pins=uart_pins[0][0])
elif 'WiPy' in machine: uart_id_range = range(0, 2) uart_pins = [[('GP12', 'GP13'), ('GP12', 'GP13', 'GP7', 'GP6')], [('GP16', 'GP17'), ('GP16', 'GP17', 'GP7', 'GP6')]] else: raise Exception('Board not supported!') # just in case we have stdio duplicated on any of the uarts pyb.repl_uart(None) for uart_id in uart_id_range: uart = UART(uart_id, 38400) print(uart) uart.init(baudrate=57600, stop=1, parity=None, pins=uart_pins[uart_id][0]) uart.init(baudrate=9600, stop=2, parity=0, pins=uart_pins[uart_id][1]) uart.init(baudrate=115200, parity=1, pins=uart_pins[uart_id][0]) uart.sendbreak() # now it's time for some loopback tests between the uarts uart0 = UART(0, 1000000, pins=uart_pins[0][0]) print(uart0) uart1 = UART(1, 1000000, pins=uart_pins[1][0]) print(uart1) print(uart0.write(b'123456') == 6) print(uart1.read() == b'123456') print(uart1.write(b'123') == 3) print(uart0.read(1) == b'1') print(uart0.read(2) == b'23') print(uart0.read() == b'')