Forums

Uart0 and uart1

Started by Pankaj March 31, 2010
I am using lpc2148, and uart0 is at 115200 buad rate.
i have to use uart0 and uart1 at same point of time, and I am struggling in code. please can someone forward me code for both uart at different baud rate

An Engineer's Guide to the LPC2100 Series

Hi Pankaj,

Did you know that baud rate settings depend on your core cpu clock
frequency? And that is not necessarily the same as your crystal frequency
(which in itself is optional)?
Presumably you are doing this in C. But even in assembly code it should not
be difficult. Look at the LPC21xx family data sheet. It explains the
procedure quite simply.

All the best,

Ahmad
On Wed, Mar 31, 2010 at 7:56 PM, Pankaj wrote:

> I am using lpc2148, and uart0 is at 115200 buad rate.
> i have to use uart0 and uart1 at same point of time, and I am struggling in
> code. please can someone forward me code for both uart at different baud
> rate
>
>
>
but its taking time, and that luxury i don't have right now. i am using
crystal of 14.7456 so maximum buad rate would be 115200 for uart0, but i
can't see anything when i m trying my code for uart1, does anyone has sample
program to help me out

On 4/1/10, Ahmad wrote:
>
> Hi Pankaj,
>
> Did you know that baud rate settings depend on your core cpu clock
> frequency? And that is not necessarily the same as your crystal frequency
> (which in itself is optional)?
> Presumably you are doing this in C. But even in assembly code it should
> not be difficult. Look at the LPC21xx family data sheet. It explains the
> procedure quite simply.
> All the best,
> Ahmad
> On Wed, Mar 31, 2010 at 7:56 PM, Pankaj wrote:
>
>> I am using lpc2148, and uart0 is at 115200 buad rate.
>> i have to use uart0 and uart1 at same point of time, and I am struggling
>> in code. please can someone forward me code for both uart at different baud
>> rate
Am 01.04.2010 06:19, schrieb Pankaj Nimgade:
> but its taking time, and that luxury i don't have right now. i am using

The day in Europe has 24 hours, I guess the same at your place.

> crystal of 14.7456 so maximum buad rate would be 115200 for uart0, but i
> can't see anything when i m trying my code for uart1, does anyone has sample
> program to help me out

UART1 == UART0, just different registers. Meanwhile you could have
debugged your code easily.

Maybe you show us, what you have done so far ?

--
42Bastian
+
| http://www.sciopta.com
| Fastest direct message passing kernel.
| IEC61508 certified.
+
Pankaj Nimgade wrote:
> ... does anyone has sample program to help me out

Did you look for examples in the files section. There is
LPC2148_Demo_compiled_with_winarm.zip for you. It seems to implement both uart0
and uart1.

--

Timo

Could you send the init routines for both your uart0 and uart1? Looks like
there must be some little register name error or bit setting error...

--Ahmad

On Thu, Apr 1, 2010 at 9:49 AM, Pankaj Nimgade wrote:

> but its taking time, and that luxury i don't have right now. i am using
> crystal of 14.7456 so maximum buad rate would be 115200 for uart0, but i
> can't see anything when i m trying my code for uart1, does anyone has sample
> program to help me out
> On 4/1/10, Ahmad wrote:
>>
>> Hi Pankaj,
>>
>> Did you know that baud rate settings depend on your core cpu clock
>> frequency? And that is not necessarily the same as your crystal frequency
>> (which in itself is optional)?
>> Presumably you are doing this in C. But even in assembly code it should
>> not be difficult. Look at the LPC21xx family data sheet. It explains the
>> procedure quite simply.
>> All the best,
>> Ahmad
>> On Wed, Mar 31, 2010 at 7:56 PM, Pankaj wrote:
>>
>>>
>>>
>>> I am using lpc2148, and uart0 is at 115200 buad rate.
>>> i have to use uart0 and uart1 at same point of time, and I am struggling
>>> in code. please can someone forward me code for both uart at different baud
>>> rate
>>>
>>
>
If you do it right, you only have to write one set of functions. You
hand that set of functions a data structure with things unique to a
given uart, like the base address of the uart. Whether you have one
uart, or a dozen, the only unique code for each of them is creating
the data structure.

Here's the structure I use. It has pointers to the send and receive
queues. At the bottom of the structure are a couple of functions to
find out if there is any received characters, or the transmitter is
full.
typedef struct uart
{
bq_t *rxq;
uint8_t *rxq_mem; /* Memory for the rxq. If NULL, malloc it. */
uint8_t rxq_sz; /* Size of queue in bytes. */
bq_t *txq;
uint8_t *txq_mem; /* Memory for the txq. If NULL, malloc it. */
uint8_t txq_sz; /* Size of queue in bytes. */
uart_regs_t *uart;
uint16_t *state; /* The state is a pointer so the uart struct
can live in flash. */

rx_pending_fp_t rx_pending;
tx_full_fp_t tx_full;
} uart_t;

An here's how the structure is populated for uart 0. Note that it is
all in program space.

static int uart0_tx_full (void *arg);
static int uart0_rx_pending (void *arg);

const uart_t uart0_cntl_block[1] {
{
.rxq = rx0_queue,
.rxq_mem = rxq0_buf,
.rxq_sz = RXQ_SIZE,
.txq = tx0_queue,
.txq_mem = txq0_buf,
.txq_sz = TXQ_SIZE,
.uart = UART0_BASE,
.state = u0_state,

.rx_pending = uart0_rx_pending,
.tx_full = uart0_tx_full,
}
};

And here are the uart0 functions for pending and full. They call
common uart functions that identifies which uart by the control block.

static int uart0_tx_full (void *arg)
{
return uart_tx_full (uart0_cntl_block);
}

static int uart0_rx_pending (void *arg)
{
return uart_rx_pending (uart0_cntl_block);
}

All the code that deals with writing and reading a uart is common to
all uarts. The lpc 2148 has 2 uarts, the lpc2378 has four. The code
size of the lpc2378 is not much bigger than that of the lpc2148.

Have fun!

DaveS.

On Wed, Mar 31, 2010 at 10:27 PM, wrote:
> Pankaj Nimgade wrote:
>> ... does anyone has sample program to help me out
>
> Did you look for examples in the files section. There is
> LPC2148_Demo_compiled_with_winarm.zip for you. It seems to implement both uart0
> and uart1.
>
> --
>
> Timo
>
>