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

Use of all 4 UARTS with LPC2378

I searched this forum for an example that could use all 4 UARTS, without success. So I developed my own. I am posting it here for your edification. This is the SERIAL.C file from the Blinky example that comes with the MCB2300 board, modified so as to use all 4 UARTS. Comments about coding technique and formatting should be directed to the authors of this routine.

Enjoy!

/******************************************************************************/
/* SERIAL.C: Low Level Serial Routines                                        */
/******************************************************************************/
/* This file is part of the uVision/ARM development tools.                    */
/* Copyright (c) 2005-2006 Keil Software. All rights reserved.                */
/* This software may only be used under the terms of a valid, current,        */
/* end user licence from KEIL for a compatible version of KEIL software       */
/* development tools. Nothing else gives you the right to use this software.  */
/******************************************************************************/

#include <LPC23xx.H>                     /* LPC23xx definitions               */

#define UART3                           /* Define which UART to use for printf*/

/* If UART 0 is used for printf                                               */
#ifdef UART0
  #define UxFDR  U0FDR
  #define UxLCR  U0LCR
  #define UxDLL  U0DLL
  #define UxDLM  U0DLM
  #define UxLSR  U0LSR
  #define UxTHR  U0THR
  #define UxRBR  U0RBR
/* If UART 1 is used for printf                                               */
#elif defined(UART1)
  #define UxFDR  U1FDR
  #define UxLCR  U1LCR
  #define UxDLL  U1DLL
  #define UxDLM  U1DLM
  #define UxLSR  U1LSR
  #define UxTHR  U1THR
  #define UxRBR  U1RBR
/* If UART 2 is used for printf                                                */
#elif defined(UART2)
  #define UxFDR  U2FDR
  #define UxLCR  U2LCR
  #define UxDLL  U2DLL
  #define UxDLM  U2DLM
  #define UxLSR  U2LSR
  #define UxTHR  U2THR
  #define UxRBR  U2RBR
/* If UART 2 is used for printf                                                */
#elif defined(UART3)
  #define UxFDR  U3FDR
  #define UxLCR  U3LCR
  #define UxDLL  U3DLL
  #define UxDLM  U3DLM
  #define UxLSR  U3LSR
  #define UxTHR  U3THR
  #define UxRBR  U3RBR
#endif


void init_serial (void)  {               /* Initialize Serial Interface       */
  #ifdef UART0
                PINSEL0 |= 0x00000050;               /* Enable TxD0 and RxD0           */
                PCLKSEL0 |= 0x00000040;              /* Send clock to UART 0           */
        #elif defined (UART1)
                PINSEL4 |= 0x00000002;                /* Enable P2.0 as TxD1               */
                PINSEL4 |= 0x00000008;                                                   /* Enable P2.1 as RxD1               */
        #elif defined (UART2)
                PCONP   |= 0x03000000;                                                   /* Turn on power to UART 2 & 3       */
                PINSEL0 |= 0x00100000;                                                   /* Enable P0.11 as TxD2              */
                PINSEL0 |= 0x00400000;               /* Enable P0.10 as RxD2              */
        #elif defined (UART3)
                PCONP   |= 0x03000000;                                                   /* Turn on power to UART 2 & 3       */
                PINSEL9 |= 0x0C000000;                                                   /* Enable P4.29 as RxD3              */
                PINSEL9 |= 0x03000000;               /* Enable P4.28 as TxD3              */
        #endif

  UxFDR    = 0;                          /* Fractional divider not used       */
  UxLCR    = 0x83;                       /* 8 bits, no Parity, 1 Stop bit     */
  UxDLL    = 78;                         /* 9600 Baud Rate @ 12.0 MHZ PCLK    */
  UxDLM    = 0;                          /* High divisor latch = 0            */
  UxLCR    = 0x03;                       /* DLAB = 0                          */
}


/* Implementation of putchar (also used by printf function to output data)    */
int sendchar (int ch)  {                 /* Write character to Serial Port    */

  while (!(UxLSR & 0x20));

  return (UxTHR = ch);
}


int getkey (void)  {                     /* Read character from Serial Port   */

  while (!(UxLSR & 0x01));

  return (UxRBR);
}