Need uart sample working code for LPC2148...

Dear All,

UART sample code whichi is given in this link “http://www.siwawi.arubi.uni-kl.de/avr_p … #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

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.

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

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

Leon

pls who know where is this code for SWI lpc2148

code with SWI using realview compiler only working well.

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.