Thursday 6 December 2018

 GPIO Ports and Registers of LPC2148.



General-purpose input/output (GPIO) is a pin on an IC (Integrated Circuit). It can be either input pin or output pin, whose behavior can be controlled at the run time. A group of these pins is called a port . It has two ports namely Port1 and Port2.



8 bit represented: (In binary: 00000000b to 11111111) (In Hex: 0x00 to 0xFF) 


16 bit represented :( In binary: 0000000000000000b to 1111111111111111) (In Hex: 0x0000 to 0xFFFF)


32 bit represented :
( In binary: 00000000000000000000000000000000b to        11111111111111111111111111111111)
 (In Hex: 0x00000000 to 0xFFFFFFFF)





PORT0: 

 

  •  It is 32 bit port with 32 pins, 28 pins can be configured as either general purpose input or output.
  •  1 of these 32 pins (P0.31) can be configured as general-purpose output only. 
  •   3 of these 32 pins (P0.24, P0.26 and P0.27) are reserved. Therefore they are not available for use.  

 

PORT1


It is also a 32-bit port. Only 16 of these 32 pins (P1.16 – P1.31) are available for use as general-purpose input or output.



Many pin these two ports have some alternate function available. If u takes example of port 0, P0.0 can be configured as the TXD pin for UART0 or as PWM1 pin as well. The functionality of each pin can be selected using the Pin Function Select Registers (PINSELx) where x represent register number.



There are some register available in LPC2148 we will see one by one.


1) Pin Function Select Registers:

 It is 32 bit register. These registers are used to select specific pin functionality.

1.  PINSEL0 : - PINSEL0 is used to configure PORT0 pins P0.0 to P0.15.


2.  PINSEL1 : - PINSEL1 is used to configure PORT0 pins P0.16 to P0.31.


3.  PINSEL2 : - PINSEL2 is used to configure PORT1 pins P1.16 to P1.31.



GPIO Register:

 


   2) IOPINx (GPIO Port Pin value register):

  This is a 32-bit wide register. This register is used to read/write the value on Port (PORT0/PORT1).




Examples:

  •   Writing 1 to P0.2 using IO0PIN



IOPIN0 = IOPIN0 | (1<<2)     or    IOPIN0=0x00000002

Here we are using LOGICAL OR operation for Masking.

  
  •     Writing 1 to P0.4-P0.0
IOPIN0 = ((1<<0)| (1<<2) | (1<<4)(1<<8))     or    IOPIN0=0x0000000F



3)  IOSETx (GPIO Port Output Set register) : 

This is a 32-bit wide register. This register is used to make pins of Port (PORT0/PORT1) HIGH. If specific bit is ‘1’ then this pin is HIGH. If bit is ‘0’ then no effect on pins.


        

  •   HIGH P0.0 pin using IOSET

IOSET0 = (1<<0)  or  IOSET0 = 0x00000001



  •  HIGH P0.4 pin using IOSET

IOSET0 = (1<<4)  or  IOSET0 = 0x00000004





4) IODIRx (GPIO Port Direction control register) :

This is a 32-bit wide register. This register individually controls the direction of each port pin. If bit is ‘1’ then this pin acts as output pin. If bit is ‘0’ then it will consider as input pin. 

 


  •  Set P0.0 as output pin

              IODIR0 = (1<<0)        or   IODIR0 = 0x00000001


  •  Set P0.4 to P0.7 as output pin and P0.0 to P0.3 as input pin

              IODIR0 = (0x0F<<4)        or   IODIR0 = 0x000000F0

 

5)  IOCLRx (GPIO Port Output Clear register):

 This is a 32-bit wide register. This register is used to make pins of Port LOW. If bit is ‘1’ then GPIO pin is LOW and if bit is ’0’ then no effect on pin.

 


  •  Clear P0.0 pin

           IOCLR0 = (1<<0)    or IOCLR0=0x00000001
  •   Clear P0.0 to P0.3 pins 
             IOCLR0=0x000000F
 
Above all GPIO register is SLOW GPIO register. In our programming we are using slow gpio register. The fast and slow gpio effect is observed when we do coding in assembly only.

 

Fast GPIO register:


  •  FIOxMASK: This is fast GPIO register. If bit is ‘0’ then it will acts as a FAST GPIO register otherwise it will slow    GPIO register.
  • FIOxPIN: Pin select register. 
  •  FIOxDIR: GPIO direction registers.
  • FIOxSET: If bit ‘1’ then set specific pin HIGH.
  • FIOxCLR: If bit ‘1’ then set specific pin LOW.

No comments:

Post a Comment