# Need uart sample working code for LPC2148...

**URL:** <https://community.sparkfun.com/t/need-uart-sample-working-code-for-lpc2148/5523>\
**Category:** MicroMod\
**Tags:** arm-lpc\
**Created:** [October 15, 2007, 11:26am UTC](https://community.sparkfun.com/t/need-uart-sample-working-code-for-lpc2148/5523 "2007-10-15T11:26:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![karunanithy](https://avatars.discourse-cdn.com/v4/letter/k/ee59a6/32.png) [@karunanithy](https://community.sparkfun.com/u/karunanithy)\
**Post date:** [October 15, 2007, 11:26am UTC](https://community.sparkfun.com/t/need-uart-sample-working-code-for-lpc2148/5523/1 "2007-10-15T11:26:55Z")

</div>

Dear All,

UART sample code whichi is given in this link “[http://www.siwawi.arubi.uni-kl.de/avr\_p … #gcc\_stdio](http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/#gcc_stdio)” are not working in LPC2148 board. I tested both interrupt driven and non-interrupt code. Both behave same, no output. I tested with KEIL MCB2140 board. The code with SWI using realview compiler only working well. The uart code build without SWI is not working at all.

Does anybody have working sample code for uart read/right/init function for LPC2148 MCU.

Thank you.

Karun

---

<div class="post-metadata">

**Author:** ![gdisirio](https://avatars.discourse-cdn.com/v4/letter/g/c4cdca/32.png) [@gdisirio](https://community.sparkfun.com/u/gdisirio)\
**Post date:** [October 15, 2007, 1:49pm UTC](https://community.sparkfun.com/t/need-uart-sample-working-code-for-lpc2148/5523/2 "2007-10-15T13:49:41Z")

</div>

Look at the link in my signature. Included in the demo there is an interrupt-driven serial driver for the LPC214x.

The driver works within the RTOS but you can easily examine the init code and the interrupt handlers.

The file you need is ./ports/ARM7-LPC214x/GCC/lpc214x\_serial.c

The demo program works as-is on the Olimex LPC-P2148 board.

---

<div class="post-metadata">

**Author:** ![Anthony\_Fremont](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@Anthony\_Fremont](https://community.sparkfun.com/u/Anthony_Fremont)\
**Post date:** [October 15, 2007, 1:58pm UTC](https://community.sparkfun.com/t/need-uart-sample-working-code-for-lpc2148/5523/3 "2007-10-15T13:58:51Z")

</div>

I’m new to this ARM stuff, but I have downloaded some code from that site. It was my experience that none of it “just worked” out of the box. Be sure your schematic agrees with the code as to which pins are connected to what.

I just got some of the UART stuff working last night on my LPC2106. I’m using a fairly simplistic receive interrupt to recieve characters and it’s working fine.

#define VICVectCntl\_ENABLE (1\<\<5)

#define VIC\_Channel\_Timer0 4

#define VIC\_Channel\_UART0 6

volatile char uart\_inchar;

static void UART\_Init(void) {

// Set to 8N1 w/DLAB

UART0\_LCR = 0x83;

// Baud rate divisor setup

UART0\_DLL = BAUD\_DIVISOR\_HIGH\_BYTE;

UART0\_DLM = BAUD\_DIVISOR\_LOW\_BYTE;

UART0\_LCR &= ~0x80;

// Setup the PINSEL to route the UART to the I/O pin

PCB\_PINSEL0 = PCB\_PINSEL0 | 0x05;

// Enable and clear FIFOs

UART0\_FCR = 0x07;

VICVectAddr1 = (unsigned long) Uart0IntHandler; // set interrupt vector in Slot 1

VICVectCntl1 = VICVectCntl\_ENABLE | VIC\_Channel\_UART0; // use it for UART0 Interrupt:

VICIntEnable = (1\<\<VIC\_Channel\_UART0); // Enable UART0 Interrupt

UART0\_IER = 0x01;

}

void **attribute** ((interrupt(“IRQ”))) Uart0IntHandler(void) {

int x;

uart\_inchar = UART0\_RBR;

x = UART0\_IIR;

x = UART0\_LSR;

VICVectAddr = 0; // Acknowledge Interrupt (rough?)

}

To send characters, just move them to the transmit FIFO:

UART0\_THR = uart\_inchar;

Keep in mind, this is crappy code as there is no error checking etc. It’s also for an LPC2106 and I have no idea if the VIC is even remotely similar between the models. The interrupt vectors for IRQ type interrupts needs to load the transfer address from the VIC to jump to the registered routine. I do it like this in my crt.S startup code:

\_vectors: ldr PC, Reset\_Addr

ldr PC, Undef\_Addr

ldr PC, SWI\_Addr

ldr PC, PAbt\_Addr

ldr PC, DAbt\_Addr

nop

ldr PC, [PC,#-0xFF0]

# ldr PC, IRQ\_Addr

ldr PC, FIQ\_Addr

Reset\_Addr: .word Reset\_Handler

Undef\_Addr: .word UNDEF\_Routine

SWI\_Addr: .word SWI\_Routine

PAbt\_Addr: .word UNDEF\_Routine

DAbt\_Addr: .word UNDEF\_Routine

IRQ\_Addr: .word IRQ\_Routine

FIQ\_Addr: .word FIQ\_Routine

---

<div class="post-metadata">

**Author:** ![leon\_heller](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/leon_heller/32/7602_2.png) [@leon\_heller](https://community.sparkfun.com/u/leon_heller)\
**Post date:** [October 15, 2007, 4:46pm UTC](https://community.sparkfun.com/t/need-uart-sample-working-code-for-lpc2148/5523/4 "2007-10-15T16:46:49Z")

</div>

There are several examples in the LPC2000 Yahoo group Files section.

Leon

---

<div class="post-metadata">

**Author:** ![euroscan](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@euroscan](https://community.sparkfun.com/u/euroscan)\
**Post date:** [February 7, 2009, 8:48pm UTC](https://community.sparkfun.com/t/need-uart-sample-working-code-for-lpc2148/5523/5 "2009-02-07T20:48:24Z")

</div>

pls who know where is this code for SWI lpc2148

```auto
code with SWI using realview compiler only working well.

```

---

<div class="post-metadata">

**Author:** ![futz](https://avatars.discourse-cdn.com/v4/letter/f/e5b9ba/32.png) [@futz](https://community.sparkfun.com/u/futz)\
**Post date:** [February 9, 2009, 4:47am UTC](https://community.sparkfun.com/t/need-uart-sample-working-code-for-lpc2148/5523/6 "2009-02-09T04:47:27Z")

</div>

> karunanithy:  
> Does anybody have working sample code for uart read/right/init function for LPC2148 MCU.

There's very simple UART code for Olimex LPC-P2148 on my site. Easy to understand, unlike so many demo source codes I looked at before just writing my own. Just click on the "LPC-P2148 Board" link and navigate from there.
