Page 1 of 2
BASICchip IO ports
Posted: Wed Feb 13, 2013 2:29 pm
by YahooArchive
I've tried this code :
#include
rw = IO(37) ' Read single pin, works OK
tt = FIO5PIN ' Read port, doesn't work. Tried 0,1,2,3,4 as well
print rw, tt
What am I doing wrong ?
Cheers,
Buzby
Re: BASICchip IO ports
Posted: Wed Feb 13, 2013 2:33 pm
by YahooArchive
Unfortunately the IO ports for the LPC11xx are not the same as the LPC17xx,
you'll have to ask NXP why.
Anyway FIOxPIN for the BASICchip is not defined in the LPC11xx.bas file.
Somewhat you are reading in your test is an uninitialized variable.
You can read the port with GPIO0_DATA, with results in bits 13:2
I had to look it up in the NXP user manual, this is the old ARM style port
Re: BASICchip IO ports
Posted: Wed Feb 13, 2013 2:34 pm
by YahooArchive
> You can read the port with GPIO0_DATA, with results in bits 13:2
I think you'll find you need to read GPIO1_DATA for Port1, with results in bits
9:0.
Re: BASICchip IO ports
Posted: Wed Feb 13, 2013 2:34 pm
by YahooArchive
Oops, haven't had my coffee yet, data is in bits 11:0, but they are masked by
address bits 13:2
Not all pins are connected to the outside world
Re: BASICchip IO ports
Posted: Wed Feb 13, 2013 2:34 pm
by YahooArchive
I've had plenty coffee, but still don't know how to read a port !.
"You can read the port with GPIO0_DATA"
What is GPIO0_DATA ?.
Is it a variable, a function, an IO address ?.
I can't find it in the 'help' file.
Please give me an example to follow.
Cheers,
Buzby
Re: BASICchip IO ports
Posted: Wed Feb 13, 2013 2:35 pm
by YahooArchive
GPIO is General Purpose I/O, if you download the NXP manual it will give you
more detail. I am sure someone can post some example code they are using for
you.
Re: BASICchip IO ports
Posted: Wed Feb 13, 2013 2:36 pm
by YahooArchive
In order to make it easier for 'axers to migrate I propose a customized version
of LPC11xx.bas (BasicChip.bas?) that has user friendly definitions such as
#define PinsA *&H50003FFC
#define PinsB *&H50013FFC
Then you could write
X = PinsB etc
and get rid of the geekspeak.
Any thoughts?
Re: BASICchip IO ports
Posted: Wed Feb 13, 2013 2:36 pm
by YahooArchive
>
> What is GPIO0_DATA ?.
>
> Is it a variable, a function, an IO address ?.
>
> I can't find it in the 'help' file.
That is the name of the register in the NXP User Manual, which really is an
important reference when using the BASICchip. I will add a pulldown menu in the
Help to open it in BASICtools.
The ARMbasic help file describes the language, not the hardware. We
intentionally do not try to duplicate NXP's documents, NXP has a hard enough
time keeping them consistent and accurate, and they have a lot more people
working on it than we have.
The definitions of all the registers commonly used for the BASICchip are in the
first line of the program #include
The source is there, and you would see
#define GPIO0_DATA *&H50003FFC '0x3FFC Port data Register (R/W)
So that when you use GPIO0_DATA you are reading or writing to the memory address
&H50003FFC which is the data register for port 0, with all bits masked ON.
I should point out as another user pointed out to me, that if you DIM your
variables, then you would have been flagged as an error the use of FIO0PIN
What I mean by this is, ARMbasic by default is like the original BASIC. Any
variable is automatically declared on its first use. As I go way back to HP
Educational BASIC which I learned in the late 60s, that is the way I like it.
But if you want to have the compiler check for mistyped or undefined variables,
it is a simple as
DIM x ' from now on all variables are checked to be pre-defined
x = FIO0PIN
>error FIO0PIN is undefined
-----------
Yes I admit it, I'm a geek. So I'm use to NXP's register nomenclature
But its also TRUE that the example programs and libraries we supply have not
been handed down on stone tablets. I'm not Moses.
So feel free to use them as a starting point. Or startup your own, a
BASICchip.bas that has the look and feel of the PICaxe world would be fine. And
it would be a welcome addition to the files section here.
PS, to read the AD ports as digital IOs you need to convert them before reading
them in parallel (check a few messages ago)
Re: BASICchip IO ports
Posted: Wed Feb 13, 2013 2:37 pm
by YahooArchive
Hi All,
Thanks for the explanations, I think I'll get it working now.
I'm not a newbie to programming, just a newbie to this platform.
Coming from the industrial world, I've used port-wide reads in all kinds of
situations where the data must be captured synchronously, such as
parallel-to-serial, or reading rotary encoders, or BCD switches, etc.
Accessing ports as bytes or words is something I would expect to see as standard
in a chip aimed at control and interface applications.
Regarding the NXP document, imagine you have just sat down to drive a hired car,
but you don't know how to turn the headlights on. Would you look in the glove
compartment for the User Manual, or contact Ford and ask for the schematics of
the whole car ?.
Bruce, if you want this chip to break into new markets it's going to need much
better documentation !.
Cheers,
Buzby.
Re: BASICchip IO ports
Posted: Wed Feb 13, 2013 2:38 pm
by YahooArchive
In addition to making links for User Manual easier, I'll add links to the
various examples easier to find. And I'll include one for parallel IO.
While I'm not suggesting it, I was curious how fast the brute force would be--
x=1000000
' next statement makes them all digital inputs in rev 8.16 firmware
y=(IO(39) and 128)+(IO(38) and 64)+(IO(37) and 32)+(IO(36) and 16)+(IO(35) and
8)+(IO(34) and 4)+(IO(33) and 2)+(IO(32) and 1)
while x
y=(IN(39) and 128)+(IN(38) and 64)+(IN(37) and 32)+(IN(36) and 16)+(IN(35) and
8)+(IN(34) and 4)+(IN(33) and 2)+(IN(32) and 1)
x-=1
loop
-------------
Finished in 9.8 msec or 9 usec per read of 8 ports combined into a byte