Using PIO OUT instruction for parallel interfaces
Posted: Tue Mar 23, 2021 8:32 am
I wrote my first few PIO programs today and had success using set and side-set mappings to have PIO programs change GPIO pins. I now want to move on to interfacing with a device that needs more pins than set or side-set mappings can provide, so I want to use an out mapping instead.
I started with
This seems to work as expected, driving GPIO pins 4 through 9 high.
I then moved on to
In this example I would've expected all six pins to remain high, but instead I observe all of them being driven low.
Why is that? Did I misunderstand how the OUT instruction works or how it interacts with the output shift register or out IO mapping?
Thanks!
I started with
Code: Select all
@rp2.asm_pio(out_init=(rp2.PIO.OUT_HIGH,)*6, out_shiftdir=rp2.PIO.SHIFT_RIGHT)
def prog0():
pull() # just hang
rp2.StateMachine(0, prog0, freq=2000, out_base=machine.Pin(4)).active(1)
I then moved on to
Code: Select all
@rp2.asm_pio(out_init=(rp2.PIO.OUT_HIGH,)*6, out_shiftdir=rp2.PIO.SHIFT_RIGHT)
def prog1():
mov(osr, 0xffffffff) # fill osr with all 1s
out(pins, 6) # output the 6 least-significant bits of osr to our 6 pins
pull()
rp2.StateMachine(0, prog1, freq=2000, out_base=machine.Pin(4)).active(1)
Why is that? Did I misunderstand how the OUT instruction works or how it interacts with the output shift register or out IO mapping?
Thanks!