UART1 on p13 and p14

21 Aug 2011

im having trouble initializing uart1 on p13 and p14

here is my init code. triple checked and referenced the lpc1768 manual and followed every single line in the example configuration step.

void uart1_init(void)
{
    LPC_SC->PCONP |= (1<<4);                //power up uart1
    LPC_SC->PCLKSEL0 |= (3<<8);             //run uart1 clock at 12MHz (prescale 8)
    
    //baud generation (115200)
    LPC_UART1->LCR |= (1<<7);               //DLAB enable
    LPC_UART1->DLL = (4<<0);                //divl
    LPC_UART1->DLM = (0<<0);                //divm
    LPC_UART1->FDR = (5<<0) | (8<<4);       //fractional baud div
    LPC_UART1->FCR |= (3<<6) | (1<<2) | (1<<1) | (1<<0);            //FIFO enable, TX and RX FIFO reset
    
    LPC_PINCON->PINSEL0 |= (0x40000000); //txd1
    LPC_PINCON->PINSEL1 |= (1<<0);       //rxd1
    LPC_PINCON->PINMODE0 |= (0x80000000);
    LPC_PINCON->PINMODE1 |= (1<<1);

    LPC_UART1->LCR |= (0<<7);               //DLAB disable
    LPC_UART1->IER |= (1<<2) | (1<<0);      //receive and transmit interrupt only
    
    LPC_UART1->LCR |= (0<<7) | (0<<3) | (0<<2) | (3<<0);        //8-n-1, DLAB=0
    
    LPC_UART1->TER |= (1<<7);               //enable transmitter
    LPC_UART1->LCR |= (0<<7);               //DLAB=0
    
    NVIC_EnableIRQ(UART1_IRQn);
}

//sending code
        LPC_UART1->THR = 'A';
        while((LPC_UART1->LSR & (1<<5)) == 0);

what possibly could be wrong with my init code

21 Aug 2011

<<quote>> LPC_UART1->LCR |= (0<<7); <</quote>>

it should have been

<<quote>> LPC_UART1->LCR &= ~(1<<7); <</quote>>

to disable DLAB

LOL