Hi all,
I am trying to output a value on a pin one bit at the time using PIO.
I would like to continuously repeat the value put in the TX FIFO until a new sm.put() instruction is run. Is there a way to refill the OSR by recycling the last putted data in the TX FIFO?
I wrote the code below, thinking it would do the trick
1) Pull without blocking (so recycling the last valid TX FIFO data) <- this is uncorrect, if TX FIFO empty X register will be moved to OSR
2) entering in a loop
3) outputting 1 bit a the time on the pin
4) When OSR empty exit loop and pull new block
Code: Select all
from machine import Pin
import rp2
@rp2.asm_pio(out_init=(rp2.PIO.OUT_LOW,)*1)
def pulse():
wrap_target()
pull(noblock) #Pull the value in the OSR
label("entry") #Entrance in the loop
out(pins,1) # Output one bit from the OSR
jmp(not_osre,"entry") #If OSR not empty jump back to the loop
wrap()
sm1 = rp2.StateMachine(0, pulse, freq=1_000_000, out_base=Pin(12))
sm1.put(234)
sm1.active(1)
Code: Select all
@rp2.asm_pio(out_init=(rp2.PIO.OUT_LOW,)*1)
def pulse():
pull() #Pull the data from OSR
mov(x,osr) #Move the OSR data to X register
wrap_target()
pull(noblock) #Pull without blocking (since FIFO empty, OSR will be updated from X register)
label("loop") #Loop for outputting one bit at the time from the OSR to the pin
out(pins,1) #Output 1 bit
jmp(not_osre,"loop") #If OSR not empty get back to the loop
wrap()
Best,
Kos