PIO push() does not show up in rx_fifo() #17463
Answered
by
GitHubsSilverBullet
ghfbsd
asked this question in
RP2040 / Pico
-
Dear All - Debugging a new PIO input program, I've encountered a puzzle where pin input does not show up when pushed to the rx_fifo. Here is the problem distilled to its essence: # piotest.py
# PIO test program
from machine import Pin
from time import sleep, ticks_ms
from rp2 import StateMachine, PIO, asm_pio
@asm_pio()
def test():
nop() # section delay 1000 ticks
set(x, 31) [6]
label('a')
nop() [29]
jmp(x_dec, 'a')
set(x, 31) [7] # section delay 1000 ticks
label('b')
nop() [29]
jmp(x_dec, 'b')
mov(isr,invert(null))
push(noblock)
irq(0) # data ready interrupt
led = Pin('LED', Pin.OUT)
def ticker(irq, buf=bytearray(8)):
led.toggle()
n = sm.rx_fifo()
print('data %d' % n)
if n > 0:
for i in range(n):
buf[i] = sm.get()
print('got %d bytes: %s' % (n,buf[0:n].hex()))
sm = StateMachine(0, test, freq=2_000)
sm.irq(handler=ticker)
sm.active(1)
try:
while True:
sleep(1)
except KeyboardInterrupt:
sm.active(0)
PIO(0).remove_program() # prevent ENOMEM on restart: PIO mem full It produces the following output:
My question is why does the pushed word not show up in the rx_fifo? Signed, Puzzled PIO Programmer |
Beta Was this translation helpful? Give feedback.
Answered by
GitHubsSilverBullet
Jun 9, 2025
Replies: 1 comment 5 replies
-
Works here, but your timing is a bit off.
You should bracket your PIO code with @asm_pio()
def test2():
wrap_target() #───────────────────────────────────
set(x, 30) [12] # 13 section delay 2000 ticks
label('loop') #
nop() [31] # 32 31×(32+32)+13 ──▶ 1997
jmp(x_dec, 'loop') [31] # 32
mov(isr,invert(null)) # 1
push(noblock) # 1
irq(0) # 1 1997+3 ──▶ 2000
wrap() #───────────────────────────────────
def ticker(irq, buf=bytearray(8)):
z = ticks_us()
s = divmod(z, 1_000_000)
mil,mic = divmod(z-s[0]*1000000, 1_000)
print(f'Timing: {s[0]}s {mil}ms {mic}µs')
led.toggle()
n = sm.rx_fifo()
print('data %d' % n)
if n > 0:
for i in range(n):
buf[i] = sm.get()
print('got %d bytes: %s' % (n,buf[0:n].hex())) |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
ghfbsd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works here, but your timing is a bit off.
You should bracket your PIO code with
wrap_target()
andwrap()