#I am trying to implement a PIO program
1 messages · Page 1 of 1 (latest)
ah
Alright, code now fixed to:
.program rs485
.side_set 1 opt
loop:
set x, 31 ; A variable used to keep track of how many bits we have gone through
out y, 32 ; Shove 32 bits from the shift register into the register `y`
bitloop: ; This is where we will loop back to until all bits are written out
out pins, y side 1 ; Set the pin high based on `y` to write out
jmp x-- bitloop side 0 ; Keep looping while bits has not performed 32 times
complete:
jmp loop ; Loop back to the beginning where we will wait for more data to write
I am now getting ValueError: invalid syntax for integer with base 10. Does it not like 31 or 32?
I think it doesn't like the "y" in out pins, y side 1
you can't use registers in place of numbers
What do you mean?
the out instruction takes the destination and the count, and count has to be a constant, not a register
look at page 323 of the datasheet, it lists all possible variants of the out instruction
Ok, after reading the actual documentation for OUT, I think I have a better understanding for the operation.
I think that I should change this around so that I pull for 32 bits (a word for the protocol) then just shift out from the OSR for each bit remaining in the OSR.
I think that should work
Maybe?
.program rs485
.side_set 1 opt
loop:
pull 32 ; Ensure we have 32 bits to shift out
set x, 31 ; A variable used to keep track of how many bits we have gone through
bitloop: ; This is where we will loop back to until all bits are written out
out pins, 1 side 1 ; Set the pin high based on `y` to write out
jmp x-- bitloop side 0 ; Keep looping while bits has not performed 32 times
complete:
jmp loop ; Loop back to the beginning where we will wait for more data to write
Also:
- I am not sure what
.side_set 1 optdoes or if I need it. - the
side 0andside 1I am trying to use to pull the second pin to be high or low in that instruction. Hopefully that is what that actually does
.side_set 1 opt tells it that for each instruction there may be optionally a sideset instruction that sets one pin to the specified value
the way you wrote it, you will have the pin set to 1 for one instruction, and to 0 for 5 instructions
I do not think I am using side correctly then at all. I am trying to operate two pins with one program if at all possible.
you can set a different set of pins for side and for out
oh, and you can change value or direction
I found that I could separate the two pins with the argument first_sideset_pin. However, I am not sure what you mean by:
you will have the pin set to 1 for one instruction, and to 0 for 5 instructions
This is the current progress on what my program looks like. The yellow line is the data line and the blue line is effectively a clock. The timing for everything looks amazing.
However, the data I am sending is not accurate. It looks like it is looping on a the first byte pulled from the shift register.
I am trying to write out: A000FF00 as a test. What is actually represented is 32 bits of A0 then 32 bits of 00, then 32 bits of FF. Where the byte is written four times.
So I guess when I pull 32, this does not pull 32 bits, but rather 8 bits? And just loops over that byte when I try to write too much from the 8 bits pulled?
The program is:
.program rs485
.side_set 1 opt
loop:
set x, 31 ; A variable used to keep track of how many bits we have gone through
pull 32 ; Ensure we have 32 bits to shift out
bitloop: ; This is where we will loop back to until all bits are written out
out pins, 1 side 1 ; Set the pin high based on `y` to write out
jmp x-- bitloop side 0 ; Keep looping while bits has not performed 32 times
complete:
jmp loop ; Loop back to the beginning where we will wait for more data to write
And this is the corresponding state machine:
sm = rp2pio.StateMachine(
arinc_write,
frequency=200000,
first_out_pin=board.D12,
out_pin_count=1,
first_sideset_pin=board.D13,
sideset_pin_count=1,
sideset_enable=True,
out_shift_right=False, # Start pulling out most sigificant bits first
auto_pull=True,
pull_threshold=32, # Make sure we can pull 32 bits
)