lpc1114 GPIO problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

lpc1114 GPIO problem

576 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mshrestha789 on Tue Jan 17 22:04:02 MST 2012
I am having problem with masking the bit for reading and writing operation.
Here's what I am doing

LPC_GPIO0->DIR |= (1<<3)|(1<<5);
LPC_GPIO0->MASKED_ACCESS[(1<<3)|(1<<5)] = (1<<3)|(1<<5);

In above code, it is suppose to mask only 3rd and 5th bits of GPIO 0. Bit it masks all bits.
Another strange thing I notice that in above code, replacing
LPC_GPIO0->MASKED_ACCESS[(1<<3)|(1<<5)] = (1<<3)|(1<<5);
with
LPC_GPIO0->MASKED_ACCESS[0] = (1<<3)|(1<<5);
makes no difference. Here in place of 0, writing any number makes no difference.

Can any one help??
Labels (1)
0 Kudos
4 Replies

486 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by PhilYoung on Fri May 25 15:18:19 MST 2012
I've been using a simple macro for this for a long time with no problems.

#define SET_GPIO(Port,Bits)(Port->MASKED_ACCESS[(Bits)] = (Bits))

#define CLR_GPIO(Port,Bits)(Port->MASKED_ACCESS[(Bits)] = (0))

this agrees with wouters code above, so if things aren't changing I suggest checking first the pin configuration and then the PCB for shorts.

technically

#define SET_GPIO(Port,Bits)(Port->MASKED_ACCESS[(Bits)] = (0xffff)) 

would also produce the same results, since it is a masked write, but the first may be more efficient as the compiler usually loads (Bits) into a register anyway

a more generic code would be
#define SET_GPIO(Port,Bits,Val)(Port->MASKED_ACCESS[(Bits)] = (Val))
0 Kudos

486 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by alexan.e on Fri May 25 11:49:47 MST 2012
In your second example you use = (1<<3)|(0<<5);

Any value ORed with 0 keeps the value it had so what is the purpose of |(0<<5)?

Alex
0 Kudos

486 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheoVanManen on Sat Feb 18 15:03:17 MST 2012
Using MASKED_ACCESS:   

It toke me some time to understand how the 'Masked_Access' worked.
Why not some example C-lines added in the User Manual?

example 1.
LPC_GPIO0->MASKED_ACCESS[(1<<3)|(1<<5)] = (1<<3)|(1<<5); //Now set only PIO0.3 & PIO0.5 high

... means: address '['(1<<3)|(1<<5)']' => only bit 3 and 5 are involved in the bitoperation.
... after the '=' (1<<3)|(1<<5) means: bit 3 is set to '1' and bit 5 = set to '1'.   

example 2.
LPC_GPIO0->MASKED_ACCESS[(1<<3)|(1<<5)] = (1<<3)|(0<<5); // is equal to
LPC_GPIO0->MASKED_ACCESS[(1<<3)|(1<<5)] = (1<<3);

... means: [(1<<3)|(1<<5)] => only bit 3 and 5 are involved in the bitoperation.
... after the '=' (1<<3)|(0<<5) means: bit 3 is set to '1' and bit 5 = set to '0'. 

Wouter, thanks for your explanation. 

0 Kudos

486 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Wouter on Fri Feb 10 08:58:31 MST 2012
Hi,

This should work just fine.
What pins do you see changing? All of GPIO0 pins? Did you set these pins as output, or are the pins set as input (default) and do you maybe see a high-level on these pins because of the pull-up resistors (enabled by default)?

You could try the following:

LPC_GPIO0->DIR = 0x0FFF;//All GPIO0 pins as output
LPC_GPIO0->DATA = 0x0000;//All GPIO0 pins low
LPC_GPIO0->MASKED_ACCESS[(1<<3)|(1<<5)] = (1<<3)|(1<<5);//Now set only PIO0.3 & PIO0.5 high
LPC_GPIO0->DATA = 0x0FFF;//All GPIO0 pins high
LPC_GPIO0->MASKED_ACCESS[(1<<3)|(1<<5)] = 0;//Now clear only PIO0.3 & PIO0.5

You can check the behavior by setting two breakpoints, each after writing to "LPC_GPIO0->MASKED_ACCESS".

Please also note that PIO0.5 is an open-drain output.

Regards,
Wouter
0 Kudos