Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:39 31 Jul 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

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

Author Message
crez

Senior Member

Joined: 24/10/2012
Location: Australia
Posts: 156
Posted: 11:43am 30 Jul 2026
Copy link to clipboard 
Print this post

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
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 2030
Posted: 12:06pm 30 Jul 2026
Copy link to clipboard 
Print this post

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
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 6006
Posted: 01:02pm 30 Jul 2026
Copy link to clipboard 
Print this post

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
PicomiteVGA PETSCII ROBOTS
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 2030
Posted: 02:20pm 30 Jul 2026
Copy link to clipboard 
Print this post

I'll see myself out  
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 6006
Posted: 04:19pm 30 Jul 2026
Copy link to clipboard 
Print this post

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
PicomiteVGA PETSCII ROBOTS
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 2030
Posted: 06:42pm 30 Jul 2026
Copy link to clipboard 
Print this post

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  
 
Print this page


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