Raspberry Pi Pico Python SDK
17
# Shift out 8 data bits, 8 execution cycles per bit
18
label("bitloop")
19
out(pins, 1)
20
jmp(x_dec, "bitloop")
21
# Assert stop bit for 8 cycles total (incl 1 for pull())
22
nop()
23
24
25
# Now we add 8 UART TXs, on pins 10 to 17. Use the same baud rate for all of them.
26 uarts = []
27
for
i in range(NUM_UARTS):
28
sm = StateMachine(
29
(PIN_BASE + i)
30
)
31
sm.active(1)
32
uarts.append(sm)
33
34
# We can print characters from each UART by pushing them to the TX FIFO
35
def
pio_uart_print(sm, s):
36
for
37
38
39
40
# Print a different message from each UART
41
for
i, u in enumerate(uarts):
42
pio_uart_print(u,
NOTE
You need to specify an initial OUT pin state in your program in order to be able to pass OUT mapping to your SM
instantiation, even though in this program it is redundant because the mappings overlap.
3.9.4. SPI
An SPI example.
Pico MicroPython Examples:
1
from
2
3 @rp2.asm_pio(out_shiftdir=0, autopull=True, pull_thresh=8, autopush=True, push_thresh=8,
sideset_init=(rp2.PIO.OUT_LOW, rp2.PIO.OUT_HIGH), out_init=rp2.PIO.OUT_LOW)
4
def
spi_cpha0():
5
# Note X must be preinitialised by setup code before first byte, we reload after sending
each byte
6
# Would normally do this via exec() but in this case it's in the instruction memory and is
only run once
7
set(x, 6)
8
# Actual program body follows
9
wrap_target()
10
pull(ifempty)
11
label("bitloop")
12
out(pins, 1)
13
in_(pins, 1)
14
jmp(x_dec, "bitloop")
15
16
out(pins, 1)
17
set(x, 6)
3.9. PIO Support
.side(1)
i, uart_tx,
freq=8
* UART_BAUD, sideset_base=Pin(PIN_BASE + i), out_base=Pin
c in s:
sm.put(ord(c))
"Hello from UART
https://github.com/raspberrypi/pico-micropython-examples/tree/master/pio/pio_spi.py
machine
import
Pin
.side(0x2)
.side(0x0)
.side(0x1)
.side(0x1)
.side(0x0)
.side(0x0)
[6]
[6]
{}!\n".format(i))
[1]
[1]
# Note this could be replaced with mov x, y for
Lines 1 - 48
23
Need help?
Do you have a question about the Pico Python SDK and is the answer not in the manual?