Wednesday, 3 December 2014

GPIO

GPIO Configurations for basic programming for ARM lpc2148


ARM 7 has two ports named as PORT0 and PORT1
Each port can be used as an output/input Port.

Basically
  • ·        PORT0 has pins PORT0 has 0 to 031 pins
  • ·        PORT1 has 16 to 031 pins.

Each Port can be used as GPIO (General Purpose input and output) or as SFR (Special Function Register).

We need Five registers to program ARM7 for GPIO Programming
  • ·        PINSELx
To use it as GPIO we have to set some register.
PINSEL0 it must be 0 to use LSB of port 0 as GPIO(0 -15)
PINSEL1 it must be 0 to use MSB of port 0 as GPIO(16-31)
PINSEL2 it must be 0 to use Port 1 as GPIO(16-31)


For example to set the PORT0 as GPIO port
We set this by PINSELO=0x00000000;
For example to set the 0th pin of PORTO as an UART0 Transmitter
WE set this by PINSELO=0x00000001;

  • IODIRx
GPIO Port Direction control register.
This register individually controls the direction of each port pin.
This word accessible register is used to control the direction of the pins when they are Configured as GPIO port pins.

Direction bit for any pin must be set according to the pin functionality.
 0-controlled PIN is INPUT
1-controlled PIN is OUTPUT

IODIRx=0x00000000;
For example if we want to set the PORT0 PINS (0-3) as output ports/individual pins as output.
We set by this IODIR0=0x0000000F; / by this the four pins 0-3 directed to be as output.
If we want to set the PORT0 pins (4-7) as input ports/individual pins as input.
We set bt this IODIR0=0xFFFFFF0F; / by this the four pins 4-7 directed to be as input.

  • IOSETx

This register is used to produce a HIGH level output at the port pins configured as GPIO in an OUTPUT mode.
GPIO Port Output Set register.
This register controls the state of output pins in conjunction with the IOCLR register.
Writing ones produces highs at the corresponding port pins. Writing zeroes has no effect.

If any pin is configured as an input or a secondary function, writing 1 to the corresponding bit in the IOSET has no effect.

When any of the PORT pins used in OUTPUT mode and to make HIGH/Enable the particular PORT pins we use this IOSET register.

If we directed the PORT0 pins (0-3) as output mode / IODIR0=0x0000000F;
And now we want to enable/high the particular pins of that PORT0 we use the IOSETO register as follows
           IOSET0=0x0000000F;/ we enable the pins (0-3) of PORT0

  • IOCLRx

This register is used to produce a LOW level output at port pins configured as GPIO in an OUTPUT mode.
GPIO Port Output Clear register.
This register controls the state of output pins.
Writing ones produces lows at the corresponding port pins and clears the corresponding bits in the IOSET register.

Writing zeroes has no effect.

When any of the PORT pins used in OUTPUT mode and to make LOW/Disable the particular PORT pins we use this IOCLR register.

If we directed the PORT0 pins (0-3) as output mode / IODIR0=0x0000000F;
And now we want to Disable/Low the particular pins of that PORT0 we use the IOCLR register as follows
            IOCLR0=0x0000000F;/ we Disable the pins (0-3) of PORT0

 IO0SET=0x00000001;     //it means 0th bit of Port 0 will be set
 IO0CLR=0x00000001;    //it means 0th bit of Port 0 will be cleared

  • IOPINx

 GPIO Port Pin value register.

This register provides the value of port pins that are configured to perform only digital functions.

The register will give the logic value of the pin regardless of whether the pin is configured for input or output, or as GPIO or an alternate digital function.

The current state of the GPIO configured port pins can always be read from this register, regardless of pin direction.

As an example,
A particular port pin may have GPIO input, GPIO output, UART receive, and PWM output as selectable functions. Any configuration of that pin will allow its current logic state to be read from the IOPIN register.

Writing to the IOPIN register stores the value in the port output register, bypassing the need to use both the IOSET and IOCLR registers to obtain the entire written value.
This feature should be used carefully in an application since it affects the entire port.
                       
if((0x00010000&IO1PIN)==0x00000000)

The above statement will execute when the status of PORT1 and given data string    equal to zero.
i.e. the status of PORT1 can be checked by using IOPINx Instruction

0 comments:

Post a Comment