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
  • No need to start new threads - you could have added a new post to the previous thread.

    Without looking at every bit you write to your registers, you do have a big error in this line:

    while (!(U1LSR && 0x20));
    


    && is a logic operation, and you want to operate on individual bits of the U1LSR register. The '&' is the required bit operator, to extract one or more bits from an integer.

    Another thing. Try to avoid magic numbers, and try to present how you decided on specific bit values when you initialize registers.

    For example:

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


    There is no information what the above two lines does. You probably knew what they did when you wrote the lines - but will you remember 6 months from now what device that gets powered up by the assign to PCONP?

    Note that many peripherial pins are available on multiple locations - your chip have _two_ TXD1 and _two_ RXD1. Shouldn't the comment tell which specific pin you enable for use as TXD1 and as RXD1?

    PINSEL0 |= 0x40000000;                /* Enable TxD1 */
    PINSEL1 |= 0x00000001;                /* Enable RxD1 */
    

    Why not present the calculation? The compiler can even perform the calculation directly in the source code - it will result in a constant value so it will not cost any extra code space or execution time:

    U1DLL = 0x34;                         /* 9600 Baud Rate @ 12MHz Clock */
    


    0x34 = 52.
    Baudrate clock must be 16 times faster than baudrate.
    So 52 * 16 * 9600 is about 8MHz.
    You mention 9600 baud @ 12 MHz clock - but do you really have a 8MHz PCLK?

Reply
  • No need to start new threads - you could have added a new post to the previous thread.

    Without looking at every bit you write to your registers, you do have a big error in this line:

    while (!(U1LSR && 0x20));
    


    && is a logic operation, and you want to operate on individual bits of the U1LSR register. The '&' is the required bit operator, to extract one or more bits from an integer.

    Another thing. Try to avoid magic numbers, and try to present how you decided on specific bit values when you initialize registers.

    For example:

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


    There is no information what the above two lines does. You probably knew what they did when you wrote the lines - but will you remember 6 months from now what device that gets powered up by the assign to PCONP?

    Note that many peripherial pins are available on multiple locations - your chip have _two_ TXD1 and _two_ RXD1. Shouldn't the comment tell which specific pin you enable for use as TXD1 and as RXD1?

    PINSEL0 |= 0x40000000;                /* Enable TxD1 */
    PINSEL1 |= 0x00000001;                /* Enable RxD1 */
    

    Why not present the calculation? The compiler can even perform the calculation directly in the source code - it will result in a constant value so it will not cost any extra code space or execution time:

    U1DLL = 0x34;                         /* 9600 Baud Rate @ 12MHz Clock */
    


    0x34 = 52.
    Baudrate clock must be 16 times faster than baudrate.
    So 52 * 16 * 9600 is about 8MHz.
    You mention 9600 baud @ 12 MHz clock - but do you really have a 8MHz PCLK?

Children