lpc1769 GPIO question from a newbie

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

lpc1769 GPIO question from a newbie

1,836 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by -0o- on Tue Aug 06 11:33:30 MST 2013
I just need some help in understanding each GPIO's location

LPC_GPIO2->FIODIR = 0x000000FF;/* P2.xx defined as Outputs */

based on this simple code above.

this sets P2.0 - P2.13 all to "outputs" right ? as comment indicates.
a gpio can be either output '1' or input '0' only a bit to represent the direction.
if an F fits in a nibble and that F can represent sixteen pins on this controller
then why 0xFF ???
I am really confused...
one F represents something and the other F represents another thing
why is a byte required to represent something a nibble is capable of doing ?
clearly there is a logical reason behind this...
for example if I wanted to set P2.4 as an output or input, will this work ?; 0x000000F4 ???

also ...
LPC_GPIO2->FIOSET = 1 << i;
i know the SET sets a pin to a HIGH or LOW so for example if i = 9
will the microcontroller shift a 1 in the ninth bit ? to make it a HIGH ??

and since only 14 pins are classified as P2 what are the extra zeros in the 0x'000000'FF
what happens if i do this 0xFF000000 or this 0x00F000F0
i know changing them will probably do something or not.. can an expert please explain what each byte or nibble position does..
here is the full code, i really need some detailed explanation
of the GPIO bits..

#include <cr_section_macros.h>
#include <NXP/crp.h>

// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

#include "lpc17xx.h"
#include "type.h"

int main (void)
{   
  uint32_t i, j;

  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();

  LPC_GPIO2->FIODIR = 0x000000FF;/* P2.xx defined as Outputs */
  LPC_GPIO2->FIOCLR = 0x000000FF;/* turn off all the LEDs */

  while(1)
  {
for(i = 0; i < 8; i++)
{
  LPC_GPIO2->FIOSET = 1 << i;
  for(j = 1000000; j > 0; j--);
}
LPC_GPIO2->FIOCLR = 0x000000FF;
for(j = 1000000; j > 0; j--);
  }
}



Thanks!
0 Kudos
Reply
4 Replies

1,214 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jomonthomasnew on Mon Oct 19 06:31:51 MST 2015
follow the link to learn configuring GPIO.
http://www.techmasterplus.com/tutorials/arm-gpio.php
0 Kudos
Reply

1,214 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mc on Tue Aug 06 17:34:00 MST 2013
It means you are setting all other pins P2.4 onward as input pins. If you do not want to touch those pins you can write

LPC_GPIO2->FIODIR |=0x000000FF;

You can also directly deal with each 8 bits (1 byte) of a 32 bit register check page 124/840 of
LPC17xx user manual UM10360_LPC17xx Rev. 2 — 19 August 2010
( http://www.nxp.com/documents/user_manual/UM10360.pdf )

LPC17xx. h file also have a structure which contains above registers. See below.

/** @brief General Purpose Input/Output (GPIO) register structure definition */
typedef struct
{
  union {
    __IO uint32_t FIODIR; /* !< Offset: 0x00 Port direction (R/W) */
    struct {
      __IO uint16_t FIODIRL;
      __IO uint16_t FIODIRH;
    };
    struct {
      __IO uint8_t  FIODIR0;
      __IO uint8_t  FIODIR1;
      __IO uint8_t  FIODIR2;
      __IO uint8_t  FIODIR3;
    };
  };

Hope it helps
0 Kudos
Reply

1,214 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by -0o- on Tue Aug 06 15:50:52 MST 2013
Hahaha.. THANKS ALOT MAN!!

I was completely overlooking it..
true true true..
so by typing FIODIR = 0x0000000f you're setting the lowest nibble P2.0 - P2.3 as outputs
true right
anyways thanks

but what are the other zero's for ??? like the highest HWORD. by fiddling with those will I be activating some kind of
High-Z or Pull-up functionality to the pin???
or they don't do anything ?

thanks again.

0 Kudos
Reply

1,214 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cfb on Tue Aug 06 14:19:15 MST 2013
Wrong!

  LPC_GPIO2->FIODIR = 0x000000FF

Sets only P2.0 to P2.7 to outputs.

0xFF is represented by 8 bits and so controls eight ports. Each bit corresponds to a port.
0 Kudos
Reply