|
发表于 2025-1-15 17:26:47
|
显示全部楼层
不知道你用的哪家的板子,代码估计也有问题。
原厂的板子用的就是无源晶振,用手触摸也不会有任何影响。
跑了一下树莓派官方的例程,八个 PIO 串口工作稳定,高低电平的宽度也是一样的。
- # Example using PIO to create a UART TX interface
- from machine import Pin
- from rp2 import PIO, StateMachine, asm_pio
- UART_BAUD = 115200
- PIN_BASE = 10
- NUM_UARTS = 8
- @asm_pio(sideset_init=PIO.OUT_HIGH, out_init=PIO.OUT_HIGH, out_shiftdir=PIO.SHIFT_RIGHT)
- def uart_tx():
- # Block with TX deasserted until data available
- pull()
- # Initialise bit counter, assert start bit for 8 cycles
- set(x, 7) .side(0) [7]
- # Shift out 8 data bits, 8 execution cycles per bit
- label("bitloop")
- out(pins, 1) [6]
- jmp(x_dec, "bitloop")
- # Assert stop bit for 8 cycles total (incl 1 for pull())
- nop() .side(1) [6]
- # Now we add 8 UART TXs, on pins 10 to 17. Use the same baud rate for all of them.
- uarts = []
- for i in range(NUM_UARTS):
- sm = StateMachine(
- i, uart_tx, freq=8 * UART_BAUD, sideset_base=Pin(PIN_BASE + i), out_base=Pin(PIN_BASE + i)
- )
- sm.active(1)
- uarts.append(sm)
- # We can print characters from each UART by pushing them to the TX FIFO
- def pio_uart_print(sm, s):
- for c in s:
- sm.put(ord(c))
- # Print a different message from each UART
- while True:
- for i, u in enumerate(uarts):
- pio_uart_print(u, "Hello from UART {}!\n".format(i))
复制代码
|
-
-
评分
-
1
查看全部评分
-
|