This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RE: PINSEL0 in LPC2148 (UART1 INITIALISATION)

in the keil ide example prog of uart the ports used for enabling uart1 is PINSEL0 = 0x00050000;,but when comparing the pin with the lpc schematics the uart1 pins are p0.8,p0.9 ,i'm not getting how the uart1 is getting enabled.

also in another example for selecting uart0 he has given that

PINSEL0 &= 0xFFFFFFF0; // Reset P0.0,P0.1 Pin Config PINSEL0 |= 0x00000001; // Select P0.0 = TxD(UART0) PINSEL0 |= 0x00000004; // Select P0.1 = RxD(UART0)

but in schematic RxD pin is p0.1 but in PINSEL0 it is given as 0x00000004,

can anyone plz explain the initialisation of uart0 & uart1 in lpc2148.

Parents
  • Have you looked at the datasheet for the processor?

    Each processor pin is represented by two bits, so to control p0.8, you have to step 16 bits into the PORTSEL0. To control p0.9, you have to step 18 bits in. To control P0.1 you have to step 2 bits in.

    Note also, that some of the processor signals can be enabled on two alternative processor pins.

Reply
  • Have you looked at the datasheet for the processor?

    Each processor pin is represented by two bits, so to control p0.8, you have to step 16 bits into the PORTSEL0. To control p0.9, you have to step 18 bits in. To control P0.1 you have to step 2 bits in.

    Note also, that some of the processor signals can be enabled on two alternative processor pins.

Children
  • ok.i agree that each processor pin is represented by two bits then for selecting p0.0 why it is represented as 0x00000001,according to you it should be 0x000002.

  • p0.0 is represented by the values 0, 1, 2, 3.
    p0.1 is represented by the values 0, 4, 8, 12.
    p0.2 is represented by the values 0, 16, 32, 48.
    ...

    "ok.i agree that each processor pin is represented by two bits then for selecting p0.0 why it is represented as 0x00000001,according to you it should be 0x000002"
    The bit 0x00000001 and 0x00000002 both belongs to the configuration of p0.0.

    "but in schematic RxD pin is p0.1 but in PINSEL0 it is given as 0x00000004,"
    The bit 0x00000004 and 0x00000008 both belongs to the configuration of p0.1.

    The code

    PINSEL0 &= 0xFFFFFFF0; // Reset P0.0,P0.1 Pin Config
    PINSEL0 |= 0x00000001; // Select P0.0 = TxD(UART0
    PINSEL0 |= 0x00000004; // Select P0.1 = RxD(UART0)
    


    Is clearing the four bits belonging to p0.0 and p0.1, and is then setting one of the bits belonging to p0.0 and one bit belonging to p0.1. In the end, all four bits have been given a well-defined value.

    For uart1, you mentioned "for enabling uart1 is PINSEL0 = 0x00050000;,but when comparing the pin with the lpc schematics the uart1 pins are p0.8,p0.9 ,i'm not getting how the uart1 is getting enabled."

    p0.8 is controlled by the bits 0x00010000 and 0x00020000.
    p0.9 is controlled by the bits 0x00040000 and 0x00080000.
    The value 0x00050000 is the sum of 0x00010000 (one of the bits controlling p0.8) and 0x00040000 (one of the bits controlling p0.9).

    In the end, you can control the values of the 16 first port pins using:

    PINSEL0 &= ~(3 << (2*n));
    PINSEL0 |= s << (2*n);
    


    n is the pin number (0..15) and s is the configuration you want (0..3).

    To control the settings for p0.16..p0.31, you would do:

    PINSEL1 &= ~(3 << (2*(n-16)));
    PINSEL1 |= s << (s*(n-16))
    

    To control the settings for p1, you would replace PINSEL0 with PINSEL2 and PINSEL1 with PINSEL3.

  • p0.8 must be controlled by the bits 00000100 if i am not wrong..can u please clarify me with that

  • If there is two bits of configuration for each pin, then you need to skip 16 bits if you are going to skip 8 pins.

    Each digit of a hexadecimal number is only four bits, i.e. setting the configuration for two I/O pins.

    1) Read my previous posts.
    2) Read the datasheet
    3) Read up a bit on hexadecimal numbers.