Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

RE: [lpc2000] UART1 for LPC2148

2006-02-24 by Joel Winarske

Hi Sutton,

> I'm having a problem with getting UART1 to work on my Embedded Artists
> prototype board.  I have a serial display that has only 1 serial line.
>  In other words, you can only transmit to the display.  I can't get
> P0.8 (UART1 TX) to send any data.  Here is my setup at 9600.  And,
> another question is 'Do I really need an interrupt just to transmit?
> It seems like throwing a char out to U1THR should suffice.  It's
> probably something simple I'm missing.  Thanks.

Below is code to implement 115200 baud at any peripheral clock frequency
based on 12MHz with lowest % error.  All items have been tested, and numbers
were derived from my utility.  This concept can be applied for any
peripheral clock or baud rate.  When I have some time I will create defines
for all standard baud rates for lowest % error.

To transmit character out of UART no interrupts are required.  Just write
the character to the UART_THR after initializing UART.

Unrelated but important when using LPC214x and USB peripheral, it states in
manual core clock must run at a minimum of 18MHz.


Joel

/*
****************************************************************
* UART w/fraction divider register values for lowest % error
****************************************************************
*/

#define BAUDRATE 115200L

#if (PCLK_UART==60MHZ)
  #define UART_DLM        0
  #define UART_DLL       24
  #define UART_MULVAL    14
  #define UART_DIVADDVAL  5
#elif (PCLK_UART==48MHZ)
  #define UART_DLM        0
  #define UART_DLL       23
  #define UART_MULVAL    15
  #define UART_DIVADDVAL  2
#elif (PCLK_UART==36MHZ)
  #define UART_DLM        0
  #define UART_DLL        8
  #define UART_MULVAL     9
  #define UART_DIVADDVAL 13
#elif (PCLK_UART==30MHZ)
  #define UART_DLM        0
  #define UART_DLL       12
  #define UART_MULVAL    14
  #define UART_DIVADDVAL  5
#elif (PCLK_UART==24MHZ)
  #define UART_DLM        0
  #define UART_DLL       13
  #define UART_MULVAL    14
  #define UART_DIVADDVAL  0
#elif (PCLK_UART==18MHZ)
  #define UART_DLM        0
  #define UART_DLL        8
  #define UART_MULVAL     9
  #define UART_DIVADDVAL  2
#elif (PCLK_UART==15MHZ)
  #define UART_DLM        0
  #define UART_DLL        3
  #define UART_MULVAL     7
  #define UART_DIVADDVAL 12
#elif (PCLK_UART==12MHZ)
  #define UART_DLM        0
  #define UART_DLL        3
  #define UART_MULVAL    12
  #define UART_DIVADDVAL 14
#elif (PCLK_UART== 9MHZ)
  #define UART_DLM        0
  #define UART_DLL        2
  #define UART_MULVAL     9
  #define UART_DIVADDVAL 13
#elif (PCLK_UART== 6MHZ)
  #define UART_DLM        0
  #define UART_DLL        3
  #define UART_MULVAL    12
  #define UART_DIVADDVAL  1
#if 0 /* bauds > 38400 are not working with fdr for pclk == 3MHz */
#elif (PCLK_UART== 3MHZ)
  #define UART_DLM        0
  #define UART_DLL        1
  #define UART_MULVAL     8
  #define UART_DIVADDVAL  5
#endif
#endif


/*
****************************************************************
* UART Init
****************************************************************
*/

#define _BAUDDIVIDE ((PCLK_UART+BAUDRATE*8L)/(BAUDRATE*16L))

  // Setup Port-Mode to alternate function
  _PINSEL0  |= _PINSEL_UART_MODE;       // Set UART-port to alt func

  _PCONP    |= (1 << _UART_PCONP_BIT);  // Enable UART unit
  _UART_IER  = 0x00;           // Initially disable all interrupts
  _UART_LCR  = 0x80;           // Set DLAB to init Baudrate gen

#ifdef UART_MULVAL             // This mcu has fraction divider
  _UART_DLM = UART_DLM;        // MSB of baud divider
  _UART_DLL = UART_DLL;        // LSB of baud divider
  _UART_FDR = (UART_MULVAL<<4) | UART_DIVADDVAL;
#else
  _UART_DLL  = (_BAUDDIVIDE & 0xFF);
  _UART_DLM  = ((_BAUDDIVIDE >> 8) & 0xFF);
#endif

  _UART_LCR &= ~0x80;          // reset DLAB to lock baudrate gen access
  _UART_LCR  = 0x03            // 8 data bits
                 |(0 << 2)     // 1 stop bit
                 |(0 << 3)     // NO parity
                 |(0 << 4)     // Parity setting (bit 5:4) does not care
                 |(0 << 6)     // Disable Break transmission
                 |(0 << 7);    // Clear DLAB

//  _UART_FCR  = 0;            // Disable FIFO
  _UART_FCR  = 3;              // Enable FIFO

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.