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
  • To implement printf you need to provide the low-level definitions for the c library functions that printf uses.

    Here is a simple example for uart:

    void uart_write_char(uint8_t byte)
    {
        while ((U0LSR & TX_HOLDING_REG_EMPTY) == 0 );
        U0THR = byte;
    }
    
    uint8_t uart_read_char(void)
    {
        while ((U0LSR & RX_DATA_READY) == 0);
        return (uint8_t)U0RBR;
    }
    
    //*************************************************************
    //
    // C Lib - LOW-LEVEL CHARACTER INPUT AND OUTPUT
    //
    //*************************************************************
    
    struct __FILE
    {
      int handle;
    };
    
    /* FILE is typedef’d in stdio.h. */
    
    FILE __stdout;
    FILE __stdin;
    FILE __stderr;
    
    int fgetc(FILE *f)
    {
        /* Your implementation of fgetc(). */
        return uart_read_char();
    };
    int fputc(int ch, FILE *stream)
    {
        uart_write_char((uint8_t)ch);
        return ch;
    }
    
    int ferror(FILE *stream)
    {
        /* Your implementation of ferror(). */
        return 0;
    }
    long int ftell(FILE *stream)
    {
        /* Your implementation of ferror(). */
        return 0;
    }
    int fclose(FILE *f)
    {
        /* Your implementation of ferror(). */
        return 0;
    }
    int fseek(FILE *f, long nPos, int nMode)
    {
        /* Your implementation of ferror(). */
        return 0;
    }
    int fflush(FILE *f)
    {
        /* Your implementation of ferror(). */
        return 0;
    }
    

    Hope this helps...

Reply
  • To implement printf you need to provide the low-level definitions for the c library functions that printf uses.

    Here is a simple example for uart:

    void uart_write_char(uint8_t byte)
    {
        while ((U0LSR & TX_HOLDING_REG_EMPTY) == 0 );
        U0THR = byte;
    }
    
    uint8_t uart_read_char(void)
    {
        while ((U0LSR & RX_DATA_READY) == 0);
        return (uint8_t)U0RBR;
    }
    
    //*************************************************************
    //
    // C Lib - LOW-LEVEL CHARACTER INPUT AND OUTPUT
    //
    //*************************************************************
    
    struct __FILE
    {
      int handle;
    };
    
    /* FILE is typedef’d in stdio.h. */
    
    FILE __stdout;
    FILE __stdin;
    FILE __stderr;
    
    int fgetc(FILE *f)
    {
        /* Your implementation of fgetc(). */
        return uart_read_char();
    };
    int fputc(int ch, FILE *stream)
    {
        uart_write_char((uint8_t)ch);
        return ch;
    }
    
    int ferror(FILE *stream)
    {
        /* Your implementation of ferror(). */
        return 0;
    }
    long int ftell(FILE *stream)
    {
        /* Your implementation of ferror(). */
        return 0;
    }
    int fclose(FILE *f)
    {
        /* Your implementation of ferror(). */
        return 0;
    }
    int fseek(FILE *f, long nPos, int nMode)
    {
        /* Your implementation of ferror(). */
        return 0;
    }
    int fflush(FILE *f)
    {
        /* Your implementation of ferror(). */
        return 0;
    }
    

    Hope this helps...

Children
No data