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

  // 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

  // Setup format: 8N1, enable access to divisor latches
  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;

  // Disable access to divisor latches
  LPC_UART->LCR = 0x03;

  // Read to reset LSR
  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

  // 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.

  • \$\begingroup\$ Can you show the circuit? This May be due to a jumper set on boot from 'x' as oppose to boot from 'y' \$\endgroup\$ – Iancovici Sep 13 '13 at 15:02
  • \$\begingroup\$ 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. \$\endgroup\$ – Farcaller Sep 13 '13 at 15:07
  • \$\begingroup\$ 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! \$\endgroup\$ – user76350 May 12 '15 at 17:35
  • \$\begingroup\$ 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). \$\endgroup\$ – 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.



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

  • \$\begingroup\$ 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? \$\endgroup\$ – bzeaman Mar 25 '16 at 8:42
  • \$\begingroup\$ IIRC that is not mentioned in the description of the periopherals itself, only in the description of the SYSCON register. \$\endgroup\$ – Wouter van Ooijen Mar 25 '16 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.