LPC1110FD20 UART Not working..

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1110FD20 UART Not working..

314 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by silex on Mon Apr 14 01:54:03 MST 2014
Hello,

I have designed a board which has LPC1110FD20 on it. I am using internal oscillator, the system runs at 12mhz. Timer32 and GPIO peripherals works as expected. An output pin is toggled on every 500ms. But problem is, UART is not working at all. As i check on oscilloscope, there is always 3.3v on UART TX pin. It does not send any data. Please find my uart init and send functions as below. I have been working on this problem for a week and still could not find a solution. I will appreciate for your help..

Thank you.


Quote:
#include "LPC11xx.h"
#include "timer32.h"
#include "gpio.h"
#include "uart.h"
#include "stdio.h"
#define TEST_TIMER_NUM0/* 0 or 1 for 32-bit timers only */

int main (void){

    SystemCoreClockUpdate();
    init_timer32(TEST_TIMER_NUM, TIME_INTERVAL);
    enable_timer32(TEST_TIMER_NUM);
   
    UARTInit(9600);

    /* Enable AHB clock to the GPIO domain. */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);
    /* Set port 0_2 to output */
    GPIOSetDir( 0, 2, 1 );
    while(1)
    {
        GPIOSetValue( 0, 2, 1 );
        delay32Ms(TEST_TIMER_NUM,500);
        sendcharCom0('a');
        sendcharCom0('a');
        sendcharCom0('a');
        GPIOSetValue( 0, 2, 0 );
        delay32Ms(TEST_TIMER_NUM,500);
    }

}



void UARTInit(uint32_t baudrate)
{

  uint32_t Fdiv;

  volatile uint32_t regVal;

  UARTTxEmpty = 1;
  UARTCount = 0;
  
  NVIC_DisableIRQ(UART_IRQn);
  LPC_IOCON->PIO1_6 &= ~0x07;    /*  UART I/O config */
  LPC_IOCON->PIO1_6 |= 0x01;     /* UART RXD */
  LPC_IOCON->PIO1_7 &= ~0x07;
  LPC_IOCON->PIO1_7 |= 0x01;     /* UART TXD */

  /* Enable UART clock */
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);
  LPC_SYSCON->UARTCLKDIV = 0x1;     /* divided by 1 */
  LPC_UART->FDR = 0x00;/* Default */
  LPC_UART->LCR = 0x83;             /* 8 bits, no Parity, 1 Stop bit */

    Fdiv = ((SystemCoreClock/LPC_SYSCON->UARTCLKDIV)/16)/baudrate ;/*baud rate */
    LPC_UART->DLM = Fdiv / 256;
    LPC_UART->DLL = Fdiv % 256;

    LPC_UART->LCR = 0x03;/* DLAB = 0 */
    LPC_UART->FCR = 0x07;/* Enable and reset TX and RX FIFO. */

  /* Read to clear the line status. */
    regVal = LPC_UART->LSR;
    regVal = LPC_UART->RBR;

  NVIC_DisableIRQ(UART_IRQn);
  LPC_UART->IER = 0;

  return;
} 


void sendcharCom0(char data) {

    int timeout = 100000;
        
    while(!(LPC_UART->LSR&0x20)) //Wait until TX FIFO empty flag to load a value
    {
      timeout--;
    if(timeout == 0) break;
    } 
    LPC_UART->THR = data;
}
Labels (1)
0 Kudos
2 Replies

266 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by silex on Mon Apr 14 03:38:35 MST 2014
Thank you very much. Problem was IOCON clock as you said. Thank you
0 Kudos

266 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Mon Apr 14 02:28:48 MST 2014
Just debug your code:

1. Is your IOCON clock enabled?

2. Are your RXD / TXD IOCON settings as expected?

3. Is your code ever reaching LPC_UART->THR?
0 Kudos