LPC 1227 and GPIO

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

LPC 1227 and GPIO

925 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by drvrh on Tue Jul 21 03:42:23 MST 2015
Hello,

I wrote my library for GPIO for LPC1227 and working in past but now doesn't work.

I have in main:

GPIOSetDir(0, 16, OUTPUT);
GPIOSetValue(0, 16, LOW);


In IO.c I have:

void GPIOSetValue( uint32_t portNum, uint32_t bitPosi, uint32_t bitVal )
{
  if (bitVal == 0)
  {
  switch (portNum) {
case 0:
LPC_GPIO0 -> CLR = (1 << bitPosi);
break;
case 1:
LPC_GPIO1 -> CLR = (1 << bitPosi);
break;
case 2:
LPC_GPIO2 -> CLR = (1 << bitPosi);
default:
break;
}
  }
  else if (bitVal >= 1)
  {
  switch (portNum){
  case 0:
  LPC_GPIO0 -> SET = (1 << bitPosi);
  break;
  case 1:
  LPC_GPIO1 -> SET = (1 << bitPosi);
  break;
  case 2:
  LPC_GPIO2 -> SET = (1 << bitPosi);
  break;
  }
  }
}

void GPIOSetDir( uint32_t portNum, uint32_t bitPosi, uint32_t dir )
{
  if(dir)
  switch (portNum) {
case 0:
LPC_GPIO0-> DIR |= 1 << bitPosi;
break;
case 1:
LPC_GPIO1-> DIR |= 1 << bitPosi;
break;
case 2:
LPC_GPIO2 -> DIR |= 1 << bitPosi;
break;
default:
break;
}
  else
  switch (portNum) {
case 0:
LPC_GPIO0 -> DIR &= ~(1 << bitPosi);
break;
case 1:
LPC_GPIO1 -> DIR &= ~(1 << bitPosi);
break;
case 2:
LPC_GPIO2 -> DIR &= ~(1 << bitPosi);
break;
default:
break;
}
}


Where I have a problem?

Original Attachment has been moved to: IO_0.c.zip

Original Attachment has been moved to: IO_0.h.zip

Labels (1)
0 Kudos
1 Reply

611 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Tue Jul 28 22:32:39 MST 2015
Hi

You are using:

LPC_GPIO0 -> CLR = (1 << bitPosi); // (1)

but you forgot the OR '|' operator:

LPC_GPIO0 -> CLR |= (1 << bitPosi); // (2)
LPC_GPIO0 -> SET |= (1 << bitPosi); // (2)


Do you see the difference? In (1)  you're setting the whole register to the (1<<bitPosi) value, but that's not what you want. In (2) you're clearing (or setting) ONLY the bit specified in bitPosi.

If you're not used to the compact sintax of C:

LPC_GPIO0 -> CLR |= (1 << bitPosi);

is the same as:

LPC_GPIO0 -> CLR = LPC_GPIO0 -> CLR | (1 << bitPosi);

(Same thing as

x+=5;

or

x = x + 5;
)
0 Kudos