# NXP LPC1114 UART doesn't work after reset

I'm building a simple circuit with LPC1114 to make a "hello world" application using UART. Trying to write all the code from scratch, to have a better understanding on what's happening.

My problem is that UART only works only after flashing (i.e. when lpc21isp asks MCU to start running code). The same code doesn't work if MCU is reset.

Here's the code I'm using:

void platform_uart_setup(uint32_t baud_rate) // 9600
{
// Make sure UART IRQ is disabled
NVIC_DisableIRQ(UART_IRQn);

// Setup pin 1_6 as RXD
LPC_IOCON->PIO1_6 &= ~0x07;
LPC_IOCON->PIO1_6 |= 0x01;

// Setup pin 1_7 as TXD
LPC_IOCON->PIO1_7 &= ~0x07;
LPC_IOCON->PIO1_7 |= 0x01;

// Enable & configure UART clock
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);
LPC_SYSCON->UARTCLKDIV = 0x1;

LPC_UART->LCR = 0x83;

// Setup baud rate, which is based on system clock
uint32_t Fdiv = platform_clock // take cpu clock (12000000 in this case)
/ LPC_SYSCON->SYSAHBCLKDIV // divide by ABH clock
/ LPC_SYSCON->UARTCLKDIV // divide further by UART clock
/ 16 // divisor latch is 16x the desired baud rate
/ baud_rate;

LPC_UART->DLM = Fdiv / 256;
LPC_UART->DLL = Fdiv % 256;

LPC_UART->FDR = 0x00 | (1 << 4) | 0;

// Enable and reset FIFOs
LPC_UART->FCR = 0x07;

LPC_UART->LCR = 0x03;

volatile uint32_t unused = LPC_UART->LSR;

// Make sure there's no data
while(( LPC_UART->LSR & (0x20|0x40)) != (0x20|0x40) )
;
while( LPC_UART->LSR & 0x01 ) {
unused = LPC_UART->RBR;
}

// Enable UART IRQ
NVIC_EnableIRQ(UART_IRQn);

// We don't care about interrupts for now
LPC_UART->IER = 0;
}

void platform_uart_putc(const char c)
{
while( !(LPC_UART->LSR & 0x20) )
;
LPC_UART->THR = c;
}


On after the reset there are absolutely no signal changes on TXD pin.

• Can you show the circuit? This May be due to a jumper set on boot from 'x' as oppose to boot from 'y' – Iancovici Sep 13 '13 at 15:02
• Well, if I add up a few leds and blink them in platform_uart_putc it blinks, so the code gets executed. The circuit is pretty simple, it's just RXD/TXD to FTDI, and two buttons for reset and 1.1 bootloader entry pin. – Farcaller Sep 13 '13 at 15:07
• thank you so much. I don't know how, but by projects stopped working after some time. UART simply didn't send nothing. I don't know why IOCON was disabled to everything. I added it on System init and averything was resolved! – user76350 May 12 '15 at 17:35
• If you're using system_LPC11xx.h you can also use SystemCoreClock after calling SystemInit and SystemCoreClockUpdate. It contains the core clock frequency (although with a default set-up probably 12000000). – bzeaman Mar 25 '16 at 14:17

I think you forgot to enable the clock to IOCON before configuring the pins for UART use, hence those assignments have no effect. But after a bootload the pins are already configured for UART, so things work.

Insert

LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16); // enable IOCON


after the IRQ setting, before configuring the pins.

PS my bmptk library supports the LPC1114. It is in C++, but you might take a look at the GPIO pins configuration (and UART initialization!), check targert/cortex/lpc1114fn28.h, and the timer initialization in targets/cortex/lpc1114.cpp

• I can't find lpc1114.cpp in your BMPTK. A search for LPC_UART didn't turn up anything. Another question, could you point me to where the user manual states where IOCON has to be enabled? – bzeaman Mar 25 '16 at 8:42
• IIRC that is not mentioned in the description of the periopherals itself, only in the description of the SYSCON register. – Wouter van Ooijen Mar 25 '16 at 8:52