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

LPC2148 using 2 UARTs at a time

I want to interface MCB2140 with a pressure sensor which will give input for every 1 second.. I connected UART0 to pressure sensor output, UART1 to serial port of PC. The pressure sensor gives the integer value as output.The UART0 will receive data from sensor and should display in hyper terminal for every 1 minute..I wrote the following code..The code gets hanged in startup file at BX R0...Please let me know any other changes required
#include <LPC21xx.H>
void init_serial (void);
int main(void) {
init_serial();

while(1)
{ int getc_serial0;
int putc_serial1;
} }
void init_serial (void) {

PINSEL0 = 0x00050005;

U0LCR = 0x00000083;

U0DLL = 98;

U0LCR = 0x00000003;

U1LCR = 0x00000083;

U1DLL = 98;

U1LCR = 0x00000003;

}

int getc_serial0(void)

{

while (!(U0LSR & 0x01));

return U0RBR;

}
int putc_serial1(void)

{

while (!(U1LSR & 0x20));

U1THR=U0RBR;

return (U1THR);

}

Parents
  • This is the code which i wrote for using 2 UARTs at a time.

    
    #include <LPC21xx.H>
    #include<stdio.h>
    void init_serial()
      {
      PINSEL0       = 0x00050005;   /* Enabling RxD0 and TxD0, RxD1 and TxD1 */
      U0LCR         = 0x00000083;    /* 8 bits, no Parity, 1 Stop bit * for UART0*/
      U0DLL         = 98;
      U0LCR         = 0x00000003;           /* DLAB = 0  for UART0*/
      U1LCR         = 0x00000083;       /* 8 bits, no Parity, 1 Stop bit for UART1*/
      U1DLL         = 98;
      U1LCR         = 0x00000003;           /* DLAB = 0 * for UART1*/
     }
    int getchar1()
    {
    if (U0LSR & 0x01)    /* If U0LSR 1st bit contains valid data then return value of U0RBR*/
    {
       return (U0RBR);
    }
       else
       {
        return 0;      /*Else return 0 to the fucntion*/
            }
    
    }
    void putchar1()
    {
    while(!(U1LSR & 0x20));      /* If U1LSR 5th bit contains valid data the copy the value of  getchar1() value to U1THR*/
    U1THR=getchar1();
    printf("%d",U1THR);
    }
    int main()
    {
    init_serial(); /* Initailization of UART1 & UART2*/
    while(1)                   /* Infinite loop*/
    {
    getchar1();   /* function for receiving data from sensor */
    putchar1();       /* function for transmitting the data to PC hyperterminal*/
    }
    }
    
    
    

Reply
  • This is the code which i wrote for using 2 UARTs at a time.

    
    #include <LPC21xx.H>
    #include<stdio.h>
    void init_serial()
      {
      PINSEL0       = 0x00050005;   /* Enabling RxD0 and TxD0, RxD1 and TxD1 */
      U0LCR         = 0x00000083;    /* 8 bits, no Parity, 1 Stop bit * for UART0*/
      U0DLL         = 98;
      U0LCR         = 0x00000003;           /* DLAB = 0  for UART0*/
      U1LCR         = 0x00000083;       /* 8 bits, no Parity, 1 Stop bit for UART1*/
      U1DLL         = 98;
      U1LCR         = 0x00000003;           /* DLAB = 0 * for UART1*/
     }
    int getchar1()
    {
    if (U0LSR & 0x01)    /* If U0LSR 1st bit contains valid data then return value of U0RBR*/
    {
       return (U0RBR);
    }
       else
       {
        return 0;      /*Else return 0 to the fucntion*/
            }
    
    }
    void putchar1()
    {
    while(!(U1LSR & 0x20));      /* If U1LSR 5th bit contains valid data the copy the value of  getchar1() value to U1THR*/
    U1THR=getchar1();
    printf("%d",U1THR);
    }
    int main()
    {
    init_serial(); /* Initailization of UART1 & UART2*/
    while(1)                   /* Infinite loop*/
    {
    getchar1();   /* function for receiving data from sensor */
    putchar1();       /* function for transmitting the data to PC hyperterminal*/
    }
    }
    
    
    

Children