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

UART Transmission in LPC2378

Dear all, I am new to LPC2378..Currently i am developing code for sending a character in serial port....Below i mentioned the code what i have written..but this is not working...i am using keil uvision4...Can anybody help me in this code????

This is my code...

#include <LPC23xx.H>
#include <stdio.h>
void delay(int);
int main (void)
{

PCONP |= 0x00000010;
PCLKSEL0 |= 0x00000300;

PINSEL0 |= 0x40000000;                /* Enable TxD1 */
PINSEL1 |= 0x00000001;                /* Enable RxD1 */
U1LCR = 0x83;                         /* 8 bits, no Parity, 1 Stop bit */
U1DLM = 0x00;
U1DLL = 0x34;                         /* 9600 Baud Rate @ 12MHz Clock */
U1FDR = 0x21;        /* U1FDR[[7:4]=MULVAL,U1FDR[[3:0]=DIVADDVAL,for baud rate generation */
U1LCR = 0x03;                          /* DLAB = 0 */
U1FCR = 0x07;                          /* enable TX amp RX FIFO ,clears TX amp RX FIFO */

while(1)
{
      U1THR = 'A';
      while (!(U1LSR && 0x20));
}
}

Parents
  • Sorry...My code is working...

    This is the code....

    #include <LPC23xx.H>
    #include <stdio.h>
    void delay(int);
    int main (void)
    {
    PINSEL0 |= 0x40000000;                /*  Enable TxD1 in  P0.15   */
    PINSEL1 |= 0x00000001;                /*  Enable RxD1 in P0.16   */
    U1LCR = 0x83;                         /* 8 bits, no Parity, 1 Stop bit */
    U1DLM = 0x00;
    U1DLL = 78;                          /* 9600 Baud Rate @ 12MHz Clock */
    U1LCR = 0x03;                          /* DLAB = 0 */
    U1FCR = 0x07;                          /* enable TX amp RX FIFO ,clears TX amp RX FIFO */
    
    while(1)
    {
          U1THR = 'A';
          while (!(U1LSR & 0x20));
    }
    }
    

    But If i use printf function in my code its not working..May i know why??Below i mentioned the code...

    #include <LPC23xx.H>
    #include <stdio.h>
    void delay(int);
    int main (void)
    {
    PINSEL0 |= 0x40000000;                /*  Enable TxD1 in  P0.15   */
    PINSEL1 |= 0x00000001;                /*  Enable RxD1 in P0.16   */
    U1LCR = 0x83;                         /* 8 bits, no Parity, 1 Stop bit */
    U1DLM = 0x00;
    U1DLL = 78;                          /* 9600 Baud Rate @ 12MHz Clock */
    U1LCR = 0x03;                          /* DLAB = 0 */
    U1FCR = 0x07;                          /* enable TX amp RX FIFO ,clears TX amp RX FIFO */
    printf("tesing...");
    while(1)
    {
          U1THR = 'A';
          while (!(U1LSR & 0x20));
    }
    }
    

Reply
  • Sorry...My code is working...

    This is the code....

    #include <LPC23xx.H>
    #include <stdio.h>
    void delay(int);
    int main (void)
    {
    PINSEL0 |= 0x40000000;                /*  Enable TxD1 in  P0.15   */
    PINSEL1 |= 0x00000001;                /*  Enable RxD1 in P0.16   */
    U1LCR = 0x83;                         /* 8 bits, no Parity, 1 Stop bit */
    U1DLM = 0x00;
    U1DLL = 78;                          /* 9600 Baud Rate @ 12MHz Clock */
    U1LCR = 0x03;                          /* DLAB = 0 */
    U1FCR = 0x07;                          /* enable TX amp RX FIFO ,clears TX amp RX FIFO */
    
    while(1)
    {
          U1THR = 'A';
          while (!(U1LSR & 0x20));
    }
    }
    

    But If i use printf function in my code its not working..May i know why??Below i mentioned the code...

    #include <LPC23xx.H>
    #include <stdio.h>
    void delay(int);
    int main (void)
    {
    PINSEL0 |= 0x40000000;                /*  Enable TxD1 in  P0.15   */
    PINSEL1 |= 0x00000001;                /*  Enable RxD1 in P0.16   */
    U1LCR = 0x83;                         /* 8 bits, no Parity, 1 Stop bit */
    U1DLM = 0x00;
    U1DLL = 78;                          /* 9600 Baud Rate @ 12MHz Clock */
    U1LCR = 0x03;                          /* DLAB = 0 */
    U1FCR = 0x07;                          /* enable TX amp RX FIFO ,clears TX amp RX FIFO */
    printf("tesing...");
    while(1)
    {
          U1THR = 'A';
          while (!(U1LSR & 0x20));
    }
    }
    

Children
  • What do you expect printf() to do? Note that for an embedded product, there are no automatic "correct" behaviour for printf(). If you want printf() to send data to a specific serial port, you can do that.

    On the other hand - if printf() is directed to send characters to uart1, then your while loop can't assume that U1THR is directly available for receiving more data - you have to consider if you want to test the state of the UART before or after you try to send characters to the port.