Use UART to send char/msg to PC sercial

11 Jan 2011

Hi Expert,

I try to carry on a experiment using UART to send char/msg to PC serial using LPC1700CMSIS library(from NXP) with sourcery g++ lite, but the msg can't show correctly in the terminal on pc.

The implementation is simple, just call the function UARTPuts/UARTPutChar provided by debug_frmwrk.c.

In my testing, sent msg "Hello world" but get some corrupt charator like "噜噜噜." on pc terminal(9600bps/8-bitdata/1-stopbit/none-parity).

LPC1700CMSIS is downloaded from http://ics.nxp.com/support/documents/microcontrollers/zip/lpc17xx.cmsis.driver.library.zip

Is anybody who has experience on this? Please suggest me. Thanks so much.

08 Sep 2011

hello jin, i'm having the same problem... i thiink it has to do somthing about clock settings but i can't figure out clock on mbed. please help if u have rsolve the issue .. Thanks a lot

08 Sep 2011

heres a code that enables UART1 on pin 25 and 26. The mbed runs at 96MHz so you may want to use that as a reference (you can always prescale though). The computation for the baud prescaler is a little tricky but the LPC17xx manual will guide you through it. This code enables the received interrupt on the line so you need the ISR for it.

/*******************************************************
            - TXD1 - DIP26
            - RXD1 - DIP25
            - 38400 bps
*******************************************************/
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 (38400)
    LPC_UART1->LCR |= (1<<7);               //DLAB enable requirement
    LPC_UART1->DLL = (14<<0);               //divl
    LPC_UART1->DLM = (0<<0);                //divm
    LPC_UART1->FDR = (4<<0) | (10<<4);      //fractional baud div
    
    LPC_UART1->FCR |= (0<<6) | (0<<3) | (1<<2) | (1<<1) | (1<<0);            //FIFO enable, TX and RX FIFO reset, no DMA
    
    LPC_PINCON->PINSEL4 |= (2<<0);          //TXD1
    LPC_PINCON->PINSEL4 |= (2<<2);          //RXD1
    LPC_PINCON->PINMODE4 |= (2<<0);         //disable pull-ups or downs
    LPC_PINCON->PINMODE4 |= (2<<2);         //disable pull-ups or downs
    
    //38400-8-n-1 frame format
    LPC_UART1->LCR &= ~(1<<7);              //DLAB disable to enable transmits and receives
    LPC_UART1->IER |= (0<<1) | (1<<0);      //receive interrupt enable only
    LPC_UART1->LCR |= (0<<3) | (0<<2) | (3<<0);             //frame format register
    LPC_UART1->TER |= (1<<7);               //enable transmitter
    
    //enable interrupt
    NVIC_SetPriority(UART1_IRQn, LOW_PR);
    NVIC_EnableIRQ(UART1_IRQn);
}