pin configuration on SuperPRO
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: pin configuration on SuperPRO
When I typed in @2009c000 (FIO0DIR) in the breakpoint terminal all my direction
registers match up to what they should be. Good sign. But when I type in
@4002c000 (PINSEL1) I get this:
4002c000: 00000050 00154000 00000000 F0000000 00000000 00000000 00000000
00000000
This breakpoint is a little bit after this line in the C code:
PINSEL1 &= 0xffc3ffff; //Changes pins P0.25 and P0.26 to GPIO
I do not see where PINSEL1 18,19,20, and 21 are. Shouldn't they be in the 2nd
block of 4 bytes over [c000 (c004)] since I called the memory at c000?
Or when I type in this to the breakpoint terminal @4002c004. I get this:
4002c004: 00154000 00000000 F0000000 00000000 00000000 00000000 00000000
4002c020: 00000000
I do not see how 00154000 hex contains PINSEL1 18,19,20, and 21. Also where is
4002c020 coming from? Does this memory call just call 8 blocks of 4 bytes?
Please explain?
Additional info if it helps:
After my PINSEL1 &= 0xffc3ffff; code I am setting them as outputs with FIO0DIR
|= (1<<25);
FIO0DIR |= (1<<26);
Thanks for your help in advance
registers match up to what they should be. Good sign. But when I type in
@4002c000 (PINSEL1) I get this:
4002c000: 00000050 00154000 00000000 F0000000 00000000 00000000 00000000
00000000
This breakpoint is a little bit after this line in the C code:
PINSEL1 &= 0xffc3ffff; //Changes pins P0.25 and P0.26 to GPIO
I do not see where PINSEL1 18,19,20, and 21 are. Shouldn't they be in the 2nd
block of 4 bytes over [c000 (c004)] since I called the memory at c000?
Or when I type in this to the breakpoint terminal @4002c004. I get this:
4002c004: 00154000 00000000 F0000000 00000000 00000000 00000000 00000000
4002c020: 00000000
I do not see how 00154000 hex contains PINSEL1 18,19,20, and 21. Also where is
4002c020 coming from? Does this memory call just call 8 blocks of 4 bytes?
Please explain?
Additional info if it helps:
After my PINSEL1 &= 0xffc3ffff; code I am setting them as outputs with FIO0DIR
|= (1<<25);
FIO0DIR |= (1<<26);
Thanks for your help in advance
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: pin configuration on SuperPRO
It looks like I can toggle P0.26 but only if I trigger a breakpoint and set
PINSEL1 manually.
Before manual set:
00154000h = 00010101 01000000 00000000
showing that AD0.0-AD0.3 are active instead of GPIO.
Set using !4002c004 0
After manual set:
00000000 00000000 00000000
Showing all pins are now GPIO
I can only do this using the breakpoint method of changing the registers. The
fact that PINSEL1 &= 0xffc3ffff; is in my code does not seem to have an affect.
Any thoughts?
PINSEL1 manually.
Before manual set:
00154000h = 00010101 01000000 00000000
showing that AD0.0-AD0.3 are active instead of GPIO.
Set using !4002c004 0
After manual set:
00000000 00000000 00000000
Showing all pins are now GPIO
I can only do this using the breakpoint method of changing the registers. The
fact that PINSEL1 &= 0xffc3ffff; is in my code does not seem to have an affect.
Any thoughts?
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: pin configuration on SuperPRO
How are you defining PINSEL1?
In LPC17xx.h the register is defined as PCB_PINSEL1
In LPX175x6x.h it uses the structure version of LPC_PINCON->PINSEL1
So you must be defining it, and I suspect wrong.
printf can be useful.
In LPC17xx.h the register is defined as PCB_PINSEL1
In LPX175x6x.h it uses the structure version of LPC_PINCON->PINSEL1
So you must be defining it, and I suspect wrong.
printf can be useful.
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: pin configuration on SuperPRO
Just found my error. I was using the Csample.c code as a template and removing
things I didn't need as I learned this board. I see that I did not remove
initAD() which was after my PINSEL command. I removed it and now it works as
far as I can tell. Thanks for all your help. This exercise has really shown me
how to use the breakpoint routine and investigate register values. Your help is
greatly appreciated.
things I didn't need as I learned this board. I see that I did not remove
initAD() which was after my PINSEL command. I removed it and now it works as
far as I can tell. Thanks for all your help. This exercise has really shown me
how to use the breakpoint routine and investigate register values. Your help is
greatly appreciated.
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: pin configuration on SuperPRO
I am still having some issues with reading a pin it seems. This is my code in
C.
if((i&2)!= (!!(LPC_GPIO1->PIN & (1<<29))))
{
printf("\n Address ");
printf("%d ", i);
printf(" Bit 1 does not match ");
printf(" %d", !!(LPC_GPIO1->PIN & (1<<29)));
}
If i=2 and P1.29=1 then this if statement reduces to "if (1!=1)" which is false
and it should not go into the block. Well it does go into this block and i do
not know why. Can someone retype my condition statement so it will work. I do
not understand what I am doing wrong.
C.
if((i&2)!= (!!(LPC_GPIO1->PIN & (1<<29))))
{
printf("\n Address ");
printf("%d ", i);
printf(" Bit 1 does not match ");
printf(" %d", !!(LPC_GPIO1->PIN & (1<<29)));
}
If i=2 and P1.29=1 then this if statement reduces to "if (1!=1)" which is false
and it should not go into the block. Well it does go into this block and i do
not know why. Can someone retype my condition statement so it will work. I do
not understand what I am doing wrong.
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: pin configuration on SuperPRO
> if((i&2)!= (!!(LPC_GPIO1->PIN & (1<<29))))
Triple negatives, really??!?!!
What is it you want to do? Yes you can write code this way, but if anyone else
has to look at it, or you come back to it in 6 months you'll be scratching your
head.
If you want to do something like i==2 and P1.29==1 then
if ((i==2) && (LPC_GPIO1->PIN &(1<<29))) {
Triple negatives, really??!?!!
What is it you want to do? Yes you can write code this way, but if anyone else
has to look at it, or you come back to it in 6 months you'll be scratching your
head.
If you want to do something like i==2 and P1.29==1 then
if ((i==2) && (LPC_GPIO1->PIN &(1<<29))) {
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: pin configuration on SuperPRO
Someone on the forum told me to do this part this way
!!(LPC_GPIO1->PIN & (1<<29)) is order to get the pin to read as a 1 or 0 and not
something like 268435456. If I print out the value of (LPC_GPIO1->PIN &(1<<29))
then it will say 268435456 not 1.
I am populating an SRAM with 16000 values. The address and data are equal so
address 32 will have data as 32 also. In my For loop I am incrementing i by 1
and writing the value of i as my address lines for the SRAM. I then want to
compare the address line which are spread over two ports with i. I figured I
would do a bitwise comparison of i with the pin.
If i is equal 10 then I am accessing memory location 10 on the SRAM and should
have a value of 10 stored in that location. So i is now equal yo 1010 and I want
to check P1.28, P1.29, P1.30, and P1.31 against those bits. I figured that this
would compare them:
if((i&1)!= (!!(LPC_GPIO1->PIN & (1<<28))))
if((i&2)!= (!!(LPC_GPIO1->PIN & (1<<29))))
if((i&3)!= (!!(LPC_GPIO1->PIN & (1<<30))))
if((i&4)!= (!!(LPC_GPIO1->PIN & (1<<31))))
If the value on the left is not equal to the value on the right then I would
print out an error message showing what i iteration and what bit position was
not correct.
!!(LPC_GPIO1->PIN & (1<<29)) is order to get the pin to read as a 1 or 0 and not
something like 268435456. If I print out the value of (LPC_GPIO1->PIN &(1<<29))
then it will say 268435456 not 1.
I am populating an SRAM with 16000 values. The address and data are equal so
address 32 will have data as 32 also. In my For loop I am incrementing i by 1
and writing the value of i as my address lines for the SRAM. I then want to
compare the address line which are spread over two ports with i. I figured I
would do a bitwise comparison of i with the pin.
If i is equal 10 then I am accessing memory location 10 on the SRAM and should
have a value of 10 stored in that location. So i is now equal yo 1010 and I want
to check P1.28, P1.29, P1.30, and P1.31 against those bits. I figured that this
would compare them:
if((i&1)!= (!!(LPC_GPIO1->PIN & (1<<28))))
if((i&2)!= (!!(LPC_GPIO1->PIN & (1<<29))))
if((i&3)!= (!!(LPC_GPIO1->PIN & (1<<30))))
if((i&4)!= (!!(LPC_GPIO1->PIN & (1<<31))))
If the value on the left is not equal to the value on the right then I would
print out an error message showing what i iteration and what bit position was
not correct.
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: pin configuration on SuperPRO
*** edited version -- last line ***
> Someone on the forum told me to do this part this way
> !!(LPC_GPIO1->PIN & (1<<29)) is order to get the pin to read as a 1 or 0 and
not something like 268435456.
You have to start thinking the way a computer stores numbers, which is in
binary. Now 268435456 may look like an odd number, but in binary that is
10000000000000000000000000000
Most programmers don't use binary, but hex representations which would be
10000000
The Windows calculator has a "programmers" view so you can do these conversions
using that.
> I am populating an SRAM with 16000 values. ...
I'm not quite following how the values stored in SRAM represent what are on the
IO pins.
>So i is now equal to 1010 and I want to check P1.28, P1.29, P1.30, and P1.31
against those bits. I figured that this would compare them:
> if((i&1)!= (!!(LPC_GPIO1->PIN & (1<<28))))
As you've probably found this may do what you want, but
> if((i&2)!= (!!(LPC_GPIO1->PIN & (1<<29))))
will not work.
(i&2) will be one of 2 values, 0 or 2
!!(LPC_GPIO1->PIN & (1<<29)) will be either 0 or 1
I'm assuming you want to check the value of P1.29 when i&2 is
true. The problem is in that case 2 will never match 0 or 1
Most programmers who use C as a main language think of FALSE being 0 and TRUE
being any other value. C++ programmers probably (I'm not one) think in terms of
BOOLEAN which are 0 and 1
In C, I think what you want is
if ((i&2) && (LPC_GPIO1->PIN & (1<<29))) {
Which is true when i has bit 1 set and P1.29 is high
> Someone on the forum told me to do this part this way
> !!(LPC_GPIO1->PIN & (1<<29)) is order to get the pin to read as a 1 or 0 and
not something like 268435456.
You have to start thinking the way a computer stores numbers, which is in
binary. Now 268435456 may look like an odd number, but in binary that is
10000000000000000000000000000
Most programmers don't use binary, but hex representations which would be
10000000
The Windows calculator has a "programmers" view so you can do these conversions
using that.
> I am populating an SRAM with 16000 values. ...
I'm not quite following how the values stored in SRAM represent what are on the
IO pins.
>So i is now equal to 1010 and I want to check P1.28, P1.29, P1.30, and P1.31
against those bits. I figured that this would compare them:
> if((i&1)!= (!!(LPC_GPIO1->PIN & (1<<28))))
As you've probably found this may do what you want, but
> if((i&2)!= (!!(LPC_GPIO1->PIN & (1<<29))))
will not work.
(i&2) will be one of 2 values, 0 or 2
!!(LPC_GPIO1->PIN & (1<<29)) will be either 0 or 1
I'm assuming you want to check the value of P1.29 when i&2 is
true. The problem is in that case 2 will never match 0 or 1
Most programmers who use C as a main language think of FALSE being 0 and TRUE
being any other value. C++ programmers probably (I'm not one) think in terms of
BOOLEAN which are 0 and 1
In C, I think what you want is
if ((i&2) && (LPC_GPIO1->PIN & (1<<29))) {
Which is true when i has bit 1 set and P1.29 is high
Last edited by YahooArchive on Wed Feb 13, 2013 12:24 pm, edited 1 time in total.
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: pin configuration on SuperPRO
>I'm not quite following how the values stored in SRAM represent what >are on
the IO pins.
I have an SRAM chip and the address and data lines are connected to IO pin. When
I ask for what is in address 24hex I should get data 24hex. It is a simple
program that is supposed to check that all memory locations are working. Each
data pin of the SRAM is connected to a separate IO pin so I am needing to check
each pin. Thanks for your help, I got it now.
the IO pins.
I have an SRAM chip and the address and data lines are connected to IO pin. When
I ask for what is in address 24hex I should get data 24hex. It is a simple
program that is supposed to check that all memory locations are working. Each
data pin of the SRAM is connected to a separate IO pin so I am needing to check
each pin. Thanks for your help, I got it now.
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: pin configuration on SuperPRO
While its possible to add memory this way, it's not really an optimum solution.
The SuperPRO has an internal 16K that is not used by either C or BASIC, unless
you change the tools a bit or access it directly.
It would be better to choose a part with enough internal memory or have the
provision for an external memory. We have used lpc178x parts which have an
external memory bus, as well as the newer lpc43xx line. So far there has not
been any demand to productize these parts, and our direction has to been to get
the low end expanded with the new BASICchip.
The other way to go would be to add a serial memory, I just saw in another forum
that the Microchip serial RAMs have added 32K and 64K devices.
Or use something like the Vdrive to add USB Flash.
The SuperPRO has an internal 16K that is not used by either C or BASIC, unless
you change the tools a bit or access it directly.
It would be better to choose a part with enough internal memory or have the
provision for an external memory. We have used lpc178x parts which have an
external memory bus, as well as the newer lpc43xx line. So far there has not
been any demand to productize these parts, and our direction has to been to get
the low end expanded with the new BASICchip.
The other way to go would be to add a serial memory, I just saw in another forum
that the Microchip serial RAMs have added 32K and 64K devices.
Or use something like the Vdrive to add USB Flash.