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