Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 21:43 23 May 2025 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 : Issue with PORT command

Author Message
stef123
Regular Member

Joined: 25/09/2024
Location: United Kingdom
Posts: 83
Posted: 04:30pm 26 Feb 2025
Copy link to clipboard 
Print this post

Hi,

i am trying to get a LCD to work (not available through the "Option LCDPANEL" command) and i am running into issues with the PORT command.


The LCDs Data Port is connected from GP2 to GP9.

So, for Data transfer, i use

Port (4,4,9,4)=lcdd (integer)

with doesnt work. According to my logic analyzer, the values are everything but not correct.

If i do it manually

pin(gp2)=lcdd and 1
pin(gp3)=lcdd and 2
pin(gp4)=lcdd and 4
pin(gp5)=lcdd and 8
pin(gp6)=lcdd and 16
pin(gp7)=lcdd and 32
pin(gp8)=lcdd and 64
pin(gp9)=lcdd and 128

it works (but this takes of course more time than a single command).

Can someone iterate through the c++-Code and look for anything which may cause this issue? Tested on the older RC6.00.00 and latest Version, both the same issue.



void cmd_port(void) {
int pin, nbr, value, code, pincode;
   int i;
getargs(&cmdline, NBRPINS * 4, (unsigned char *)",");

if((argc & 0b11) != 0b11) error("Invalid syntax");
   if(!strchr((char *)cmdline,')'))error ("Syntax");
   // step over the equals sign and get the value for the assignment
while(*cmdline && tokenfunction(*cmdline) != op_equal) cmdline++;
if(!*cmdline) error("Invalid syntax");
++cmdline;
if(!*cmdline) error("Invalid syntax");
value = getinteger(cmdline);
   uint64_t mask=0,setmask=0, readmask=gpio_get_all64();

   for(i = 0; i < argc; i += 4) {
    code=0;
    if(!(code=codecheck(argv[i])))argv[i]+=2;
    pincode = getinteger(argv[i]);
       nbr = getinteger(argv[i + 2]);
       if(nbr < 0 || (pincode == 0 && code!=0) || (pincode<0)) error("Invalid argument");

       while(nbr) {
        if(!code)pin=codemap(pincode);
        else pin=pincode;
           if(IsInvalidPin(pin) || !(ExtCurrentConfig[pin] == EXT_DIG_OUT )) error("Invalid output pin");
           mask |=(1<<PinDef[pin].GPno);
           if(value & 1)setmask |= (1<<PinDef[pin].GPno);
           value >>= 1;
           nbr--;
           pincode++;
       }
   }
   readmask &=mask;
   gpio_xor_mask64(setmask ^ readmask);
}


Is it correct to XOR setmask with readmask? I suppose when for example readmask Bit 0 is being 1 and Setmask is also 1, it would XOR into zero. But only my assumption.

Thanks !
Stef
Edited 2025-02-27 02:41 by stef123
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1192
Posted: 04:50pm 26 Feb 2025
Copy link to clipboard 
Print this post

Not in a good location right now but I can forward some code that I experimented with a long time ago to read and debounce a port.

Might give clues(?)

SetPin GP2, DIN, PULLUP
SetPin GP3, DIN, PULLUP
SetPin GP4, DIN, PULLUP
SetPin GP5, DIN, PULLUP
SetPin GP6, DIN, PULLUP
SetPin GP7, DIN, PULLUP

portread% = 0
filtered% = 0

scan_period% = 5
scan_count% = 0

settick scan_period%, scanin  'Read the port every 5ms


do

if scan_count% > 7 then 'State of port hasn't changed for at least 8 scans
if filtered% and not 1 then print "2"
   if filtered% and not 2 then print "3"    
if filtered% and not 4 then print "4"
   if filtered% and not 8 then print "5"
   if filtered% and not 16 then print "6"
if filtered% and not 32 then print "7"
   scan_count%=0
 end if

loop

sub scanin

if scan_count% = 0 then
 portread% = port(gp2,6)
 inc scan_count%
elseif portread% <> port(gp2,6) then
   scan_count% = 0
else
   inc scan_count%
   if scan_count% = 8 then
     filtered% = portread%
   end if  
end if

end sub
 
stef123
Regular Member

Joined: 25/09/2024
Location: United Kingdom
Posts: 83
Posted: 04:53pm 26 Feb 2025
Copy link to clipboard 
Print this post

Thank you, but i'm writing to a Port using the PORT command, not reading from GPIO  
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1192
Posted: 05:11pm 26 Feb 2025
Copy link to clipboard 
Print this post

I think similar applies though (don't have manual with me)

Don't you need to specify the first output followed by the number of other outputs?

Edit: Like Port(4,8)=
Edited 2025-02-27 03:17 by PhenixRising
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10089
Posted: 05:14pm 26 Feb 2025
Copy link to clipboard 
Print this post

What version are you running? There was a bug in the port command introduced in 6.00.01 that is fixed in the latest betas.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7584
Posted: 05:15pm 26 Feb 2025
Copy link to clipboard 
Print this post

This should work.
PORT(GP0,5) = 7
would write 7 to the port defined by bits GP0, GP1,GP2,GP3 & GP4
Using GP numbers avoids having to skip over GND pins.

Always avoid using absolute pin numbers if at all possible. They are specific to one particular module. GPn numbers are transferable between all RPnnnn chips (so far) no matter what shape or how many physical pins the module has. GP0, for example, may not always be on pin 1 of the module, it could be anywhere.

.
Edited 2025-02-27 03:18 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
stef123
Regular Member

Joined: 25/09/2024
Location: United Kingdom
Posts: 83
Posted: 05:21pm 26 Feb 2025
Copy link to clipboard 
Print this post

Command goes as follows

PORT (Start Pin (bit 0-3), Number of Pins to be used for Bits 0-3, next Start pin (Bits 4-7), Number of Pins to be used for Bit 4-7)

So if i issue Port (4,4,9,4) (physical Pin Numbers)

means write Biits 0-3 to GP2-GP5 and Bits 4-7 to GP6-GP9 (Bit 4-7) in order to form an 8 Bit Output.


You can't for example issue only "Port (4,8)" because you would run into a physical pin which is is not an I/O Pin (Pin 8=GND).
 
stef123
Regular Member

Joined: 25/09/2024
Location: United Kingdom
Posts: 83
Posted: 05:25pm 26 Feb 2025
Copy link to clipboard 
Print this post

Matherp, i am running exactly 6.00.01 and was also running 6.00.00 RC14 for error comparison.

I will check out the Beta Version.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7584
Posted: 05:28pm 26 Feb 2025
Copy link to clipboard 
Print this post

This is exactly why using the GP numbers is better. You can ignore the GND pins.
If you use absolute pin numbers your program will run on a normal Pico or Pico 2 but probably not on a PGA2350, for example.

PORT(GP0,8) is valid.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
stef123
Regular Member

Joined: 25/09/2024
Location: United Kingdom
Posts: 83
Posted: 05:31pm 26 Feb 2025
Copy link to clipboard 
Print this post

Yep, latest Beta works as expected ! Thanks for the hint!

I was totally confused because i've already had written an RP2040-Assembly-Program for this specific LCD and there it worked without any issues. Thank God that i have a logic analyzer...
 
stef123
Regular Member

Joined: 25/09/2024
Location: United Kingdom
Posts: 83
Posted: 05:34pm 26 Feb 2025
Copy link to clipboard 
Print this post

I've used the raw pin numbers because there is no hint in the manual that combining GP-Numbers with the full amount of Pins being used is allowed.

Of course i tried to replace the raw Pin Numbers with their GP-Counterpart, but sticked to dividing it into 2*4 Bits, assuming that i otherwise would run into an invalid Pin.

Nice Tip, thank you!
Edited 2025-02-27 03:42 by stef123
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1192
Posted: 05:52pm 26 Feb 2025
Copy link to clipboard 
Print this post

Love the PORT command and function  
 
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 2025