Menu
JAQForum Ver 19.10.27

Forum Index : Microcontroller and PC projects : pio wait instruction not seeing gpio state on RP2350

Posted: 11:43am
30 Jul 2026
Copy link to clipboard
crez
Senior Member


I was going through the handy step-by-step PIO guide by Volhout. The example code below was not behaving as expected. The pulsing on gp0 should stop when gp2 is low, but the pulsing did not start when gp2 was set hi. gp2 was always being read as low. The cure was to move the 'setpin gp2,dout' to the start of the program. The RP2350 has something called 'pad isolation latches', which the RP2040 does not have. The PIO initialization does not work correctly unless the pad isolation is disabled first (accomplished by the setpin dout). I'm no expert with PIO, so my explanation may be a bit off. Using PiPicoBT.

'disconnect ARM from GP0
setpin gp0,pio1

'configure pio1
p=Pio(pinctrl 0,1,,,,gp0,)
f=1000 * 6 'Hz

'line code comment
' 0 � � E081 SET GP0 output
' 1 � � 2082 WAIT GP2=1
' 2 � � E201 � �SET gp0 high, dly=2
' 3 � � E000 � �SET gp0 low
' 4 � � 0001 � �JMP to 1

'program pio1
pio program line 1,0,&hE081
pio program line 1,1,&h2082
pio program line 1,2,&hE201
pio program line 1,3,&hE000
pio program line 1,4,&h0001


'write the configuration
PIO init machine 1,0,f,p,,,0

'start the pio1 code
PIO start 1,0


'toggle GP2 in MMBasic
Setpin gp2,dout '---------------<<<<<-----move this to program start

do
�pin(gp2) = 1 - pin(gp2) 'toggle pin GP2
�pause 100
loop
 
Posted: 12:06pm
30 Jul 2026
Copy link to clipboard
PhenixRising
Guru

Two things; gp2 hasn't been configured as an output
setpin gp2,dout



Is this a workable toggle?
pin(gp2) = 1 - pin(gp2) 'toggle pin GP2


Edit: Yes it is  

I would:

pin(gp2)= not pin(gp2)

Edited 2026-07-30 22:09 by PhenixRising
 
Posted: 01:02pm
30 Jul 2026
Copy link to clipboard
Volhout
Guru

Good find crez.
The examples where developped on 2040, and I did not envision this, but it makes sense.

There are more examples where it could go wrong: the logic analyzer example could also fail.

Volhout
 
Posted: 02:20pm
30 Jul 2026
Copy link to clipboard
PhenixRising
Guru

I'll see myself out  
 
Posted: 04:19pm
30 Jul 2026
Copy link to clipboard
Volhout
Guru

In a week I 'll be home, and look into it. Phenix looked at another pio program (stepper pulse decoder) and also noticed it did not work. This one probably because the setpin was brute force moved up to make it work, and then it escaped the define.

So my homework.: make sure all pio programs are to modify to make them work eith 60300 for both 2040 and 3350

Volhout
Edited 2026-07-31 02:19 by Volhout
 
Posted: 06:42pm
30 Jul 2026
Copy link to clipboard
PhenixRising
Guru

Of course I understand nothing of PIO programming but the issues I have with both the step/dir and the quad decoder is that, due to the FIFO, the current sample is not really the latest value. Not really an issue with the quad decoder because even at steady state, there is still at least a 1bit oscillation and so it updates but the step/dir never updates the latest actual count value. Gemini showed how to directly read the register (not the FIFO) but the instruction wasn't recognised.

I believe I explained this correctly  
 
Posted: 07:20am
31 Jul 2026
Copy link to clipboard
crez
Senior Member


the PIO pulse width measurement example in the same tutorial also was behaving strangely so I tried the same fix for the RP2350 and it looked good after that.
 


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026