EmbeddedRelated.com
Forums
Memfault Beyond the Launch

LPC2148 Uart Problem

Started by SUBRAMANIUM April 25, 2011
Hello
am using LPC2148 controller. I have started to use WinArm complier now. Previously I was using Keil compiler. Now I am able to print data using both uart0 n uart1 but am not able to receive the data from either ports.
my initialization routine is below.
Kindly help. thanks in advance.
/**
* Initialize UART0, setup pin select, clock, parity, stop bits, FIFO, etc.
*
* @param baudrate Baudrate
* @param data_bits Number of data bits [5,6,7,8]
* @param parity Parity ['n','N,'o','O','e','E','1','0']
* @param stop_bits Number of stop bits [1,2]
*
* @return false if the interrupt handler could not be installed in the VIC table,
* true otherwise.
*/
bool_t uart0_init(uint32_t baudrate, uint8_t data_bits, char parity, uint8_t stop_bits)
{
uint32_t dummy;
uint32_t p;
uint32_t Fdiv, fdr;

// Clear RX & TX buffers.
memset(&uart0_buffer,0,sizeof(uart0_buffer));
uart0_buffer.tx_fifo_empty = true;

PINSEL0 = (PINSEL0&0xfffffff0)|0x00000005; // Enable RxD0 and TxD0

// disable any interrupts currently enabled.
U0IER = 0;
// clear any possible interrupt sources.
dummy = U0IIR;
dummy = U0RBR;
dummy = U0LSR;

// Setup communication parameters.
p = 0;
if (parity=='o' || parity=='O') p = 0x08;
else if (parity=='e' || parity=='E') p = 0x18;
else if (parity=='1') p = 0x28;
else if (parity=='0') p = 0x38;
// Setup data bits [5,8], stop bits [1,2] & parity ['n','o','e','1','0'].
U0LCR = 0x80 + ((data_bits-5)&0x3) + (((stop_bits-1)&0x1)<<1) + p;
// Setup baud rate.
Fdiv = uart_calculate_baudrate(baudrate,&fdr);
//Fdiv = (Fpclk/16)/baudrate;
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0FDR = fdr;

// Better precision for 115200 @ PCLK` MHz
//U0DLM = 0;
//U0DLL = 30;
//U0FDR = (12<<4) | 1;

U0LCR &= 0x7f; // DLAB = 0.

// Enable and reset TX and RX FIFO, RX fifo trigger level is 1 character.
U0FCR = 0x07;

if (irq_install(UART0_INT,(void*)uart0_handler)=se)
{
return false;
}

// Enable RX, TX & line status interrupts.
U0IER = IER_RBR | IER_THRE | IER_RLS;
return true;
}

An Engineer's Guide to the LPC2100 Series

Check the sample code provided @
Blueboard-lpc2148

On Mon, Apr 25, 2011 at 5:46 PM, SUBRAMANIUM wrote:

> Hello
> am using LPC2148 controller. I have started to use WinArm complier now.
> Previously I was using Keil compiler. Now I am able to print data using both
> uart0 n uart1 but am not able to receive the data from either ports.
> my initialization routine is below.
> Kindly help. thanks in advance.
> /**
> * Initialize UART0, setup pin select, clock, parity, stop bits, FIFO, etc.
> *
> * @param baudrate Baudrate
> * @param data_bits Number of data bits [5,6,7,8]
> * @param parity Parity ['n','N,'o','O','e','E','1','0']
> * @param stop_bits Number of stop bits [1,2]
> *
> * @return false if the interrupt handler could not be installed in the VIC
> table,
> * true otherwise.
> */
> bool_t uart0_init(uint32_t baudrate, uint8_t data_bits, char parity,
> uint8_t stop_bits)
> {
> uint32_t dummy;
> uint32_t p;
> uint32_t Fdiv, fdr;
>
> // Clear RX & TX buffers.
> memset(&uart0_buffer,0,sizeof(uart0_buffer));
> uart0_buffer.tx_fifo_empty = true;
>
> PINSEL0 = (PINSEL0&0xfffffff0)|0x00000005; // Enable RxD0 and TxD0
>
> // disable any interrupts currently enabled.
> U0IER = 0;
> // clear any possible interrupt sources.
> dummy = U0IIR;
> dummy = U0RBR;
> dummy = U0LSR;
>
> // Setup communication parameters.
> p = 0;
> if (parity=='o' || parity=='O') p = 0x08;
> else if (parity=='e' || parity=='E') p = 0x18;
> else if (parity=='1') p = 0x28;
> else if (parity=='0') p = 0x38;
> // Setup data bits [5,8], stop bits [1,2] & parity ['n','o','e','1','0'].
> U0LCR = 0x80 + ((data_bits-5)&0x3) + (((stop_bits-1)&0x1)<<1) + p;
> // Setup baud rate.
> Fdiv = uart_calculate_baudrate(baudrate,&fdr);
> //Fdiv = (Fpclk/16)/baudrate;
> U0DLM = Fdiv / 256;
> U0DLL = Fdiv % 256;
> U0FDR = fdr;
>
> // Better precision for 115200 @ PCLK` MHz
> //U0DLM = 0;
> //U0DLL = 30;
> //U0FDR = (12<<4) | 1;
>
> U0LCR &= 0x7f; // DLAB = 0.
>
> // Enable and reset TX and RX FIFO, RX fifo trigger level is 1 character.
> U0FCR = 0x07;
>
> if (irq_install(UART0_INT,(void*)uart0_handler)=se)
> {
> return false;
> }
>
> // Enable RX, TX & line status interrupts.
> U0IER = IER_RBR | IER_THRE | IER_RLS;
> return true;
> }
>
>
>

--
Warm regards
Ashwin
Director, NGX Technologies Pvt. Ltd.

Memfault Beyond the Launch