EmbeddedRelated.com
Forums

LPC2138 - reading RXD0 Receiver input for UART0 to hyper terminal

Started by priyankvmaiya2 February 21, 2010
Hi,
I have an external device(board) which gives data at the rate of 240 bytes per second. This data is sent at a baud rate of 4800 baud, 8 bits, 1 stop bit, and no parity.
I need to collect this data into my lpc2138 board and print it to hyperterminal via UART0

To print some sample string from the lpc2138 board to the hyperterminal via UART0, I had to set the baud rate to 9600 (i.e. without the external device). This works.

But when I change the baud rate to 4800, my board does not detect any data from the external device. I have connected the external device to the pin P0.1 which is RXD0 Receiver input for UART0. i.e. The UART0_LSR bit for Read Buffer Register is always 0 which means the register is empty.
I am not using interrupt for this.

Can anyone please tell me where I am going wrong.
I have pasted my code snippet below.

PINSEL0 = 0x5; // Enable RxD0 and TxD0
UART0_LCR = 0x00000083; // 8 bits, no Parity, 1 Stop bit
UART0_DLL = 0x0000000C; // 4800 Baud Rate @ 60MHz VPB Clock
UART0_DLM = 0x00000003; // 4800 Baud Rate @ 60MHz VPB Clock
UART0_LCR = 0x00000003; // DLAB = 0
UART0_FCR = 0x00000007; // Enable and reset TX and RX FIFO.

while(1)
{
recv_byte = getchar();
dec2bin(recv_byte, binary);
}

int getchar (void)
{
while (!(UART0_LSR & 0x01)); // Does not execute beyond this point.
return (UART0_RBR);
}

Thanks,
Priyank

An Engineer's Guide to the LPC2100 Series

Hi
Maybe you have wrong set in clock section.
If you have pclk 15Mhz (60/4 Reset Value)then good sets is DLL=195
DLM =0.Try to use this
http://ics.nxp.com/support/documents/microcontrollers/xls/lpc2000.uart.baudrate.calculator.xls
If im wrong please correct.

Regards
Tomek
--- In l..., "priyankvmaiya2" wrote:
>
> Hi,
> I have an external device(board) which gives data at the rate of 240 bytes per second. This data is sent at a baud rate of 4800 baud, 8 bits, 1 stop bit, and no parity.
> I need to collect this data into my lpc2138 board and print it to hyperterminal via UART0
>
> To print some sample string from the lpc2138 board to the hyperterminal via UART0, I had to set the baud rate to 9600 (i.e. without the external device). This works.
>
> But when I change the baud rate to 4800, my board does not detect any data from the external device. I have connected the external device to the pin P0.1 which is RXD0 #65533;" Receiver input for UART0. i.e. The UART0_LSR bit for Read Buffer Register is always 0 which means the register is empty.
> I am not using interrupt for this.
>
> Can anyone please tell me where I am going wrong.
> I have pasted my code snippet below.
>
> PINSEL0 = 0x5; // Enable RxD0 and TxD0
> UART0_LCR = 0x00000083; // 8 bits, no Parity, 1 Stop bit
> UART0_DLL = 0x0000000C; // 4800 Baud Rate @ 60MHz VPB Clock
> UART0_DLM = 0x00000003; // 4800 Baud Rate @ 60MHz VPB Clock
> UART0_LCR = 0x00000003; // DLAB = 0
> UART0_FCR = 0x00000007; // Enable and reset TX and RX FIFO.
>
> while(1)
> {
> recv_byte = getchar();
> dec2bin(recv_byte, binary);
> }
>
> int getchar (void)
> {
> while (!(UART0_LSR & 0x01)); // Does not execute beyond this point.
> return (UART0_RBR);
> }
>
>
>
> Thanks,
> Priyank
>

Hi,
Thanks for the reply.
But the board i have i.e lpc2138 has a clock of 60MHz. I confirmed this by
the sample string, which i printed onto the hyperterminal via UART0. For
9600 baud, I had to give 390, which matched the pclk of 60 MHz. I was able
to see the string printed on the hyperterminal.

I was wondering, if i am missing something like, setting/initializing any
register in the UART0. Or is it a must to use interrupts for receiving data
from the RX pin.

Regards,
Priyank

On Sun, Feb 21, 2010 at 7:44 PM, ro.rente wrote:

> Hi
> Maybe you have wrong set in clock section.
> If you have pclk 15Mhz (60/4 Reset Value)then good sets is DLL5
> DLM =0.Try to use this
>
> http://ics.nxp.com/support/documents/microcontrollers/xls/lpc2000.uart.baudrate.calculator.xls
> If im wrong please correct.
>
> Regards
> Tomek
> --- In l... ,
> "priyankvmaiya2" wrote:
> >
> > Hi,
> > I have an external device(board) which gives data at the rate of 240
> bytes per second. This data is sent at a baud rate of 4800 baud, 8 bits, 1
> stop bit, and no parity.
> > I need to collect this data into my lpc2138 board and print it to
> hyperterminal via UART0
> >
> > To print some sample string from the lpc2138 board to the hyperterminal
> via UART0, I had to set the baud rate to 9600 (i.e. without the external
> device). This works.
> >
> > But when I change the baud rate to 4800, my board does not detect any
> data from the external device. I have connected the external device to the
> pin P0.1 which is RXD0 #65533;" Receiver input for UART0. i.e. The
> UART0_LSR bit for Read Buffer Register is always 0 which means the register
> is empty.
>
> > I am not using interrupt for this.
> >
> > Can anyone please tell me where I am going wrong.
> > I have pasted my code snippet below.
> >
> > PINSEL0 = 0x5; // Enable RxD0 and TxD0
> > UART0_LCR = 0x00000083; // 8 bits, no Parity, 1 Stop bit
> > UART0_DLL = 0x0000000C; // 4800 Baud Rate @ 60MHz VPB Clock
> > UART0_DLM = 0x00000003; // 4800 Baud Rate @ 60MHz VPB Clock
> > UART0_LCR = 0x00000003; // DLAB = 0
> > UART0_FCR = 0x00000007; // Enable and reset TX and RX FIFO.
> >
> > while(1)
> > {
> > recv_byte = getchar();
> > dec2bin(recv_byte, binary);
> > }
> >
> > int getchar (void)
> > {
> > while (!(UART0_LSR & 0x01)); // Does not execute beyond this point.
> > return (UART0_RBR);
> > }
> >
> >
> >
> > Thanks,
> > Priyank
> >
>
Hi,
Could anyone please help me with this.

Thanks,
Priyank

On Sun, Feb 21, 2010 at 10:39 PM, Priyank Maiya wrote:

> Hi,
> Thanks for the reply.
> But the board i have i.e lpc2138 has a clock of 60MHz. I confirmed this by
> the sample string, which i printed onto the hyperterminal via UART0. For
> 9600 baud, I had to give 390, which matched the pclk of 60 MHz. I was able
> to see the string printed on the hyperterminal.
>
> I was wondering, if i am missing something like, setting/initializing any
> register in the UART0. Or is it a must to use interrupts for receiving data
> from the RX pin.
>
> Regards,
> Priyank
> On Sun, Feb 21, 2010 at 7:44 PM, ro.rente wrote:
>
>> Hi
>> Maybe you have wrong set in clock section.
>> If you have pclk 15Mhz (60/4 Reset Value)then good sets is DLL5
>> DLM =0.Try to use this
>>
>> http://ics.nxp.com/support/documents/microcontrollers/xls/lpc2000.uart.baudrate.calculator.xls
>> If im wrong please correct.
>>
>> Regards
>> Tomek
>> --- In l... ,
>> "priyankvmaiya2" wrote:
>> >
>> > Hi,
>> > I have an external device(board) which gives data at the rate of 240
>> bytes per second. This data is sent at a baud rate of 4800 baud, 8 bits, 1
>> stop bit, and no parity.
>> > I need to collect this data into my lpc2138 board and print it to
>> hyperterminal via UART0
>> >
>> > To print some sample string from the lpc2138 board to the hyperterminal
>> via UART0, I had to set the baud rate to 9600 (i.e. without the external
>> device). This works.
>> >
>> > But when I change the baud rate to 4800, my board does not detect any
>> data from the external device. I have connected the external device to the
>> pin P0.1 which is RXD0 #65533;" Receiver input for UART0. i.e. The
>> UART0_LSR bit for Read Buffer Register is always 0 which means the register
>> is empty.
>>
>> > I am not using interrupt for this.
>> >
>> > Can anyone please tell me where I am going wrong.
>> > I have pasted my code snippet below.
>> >
>> > PINSEL0 = 0x5; // Enable RxD0 and TxD0
>> > UART0_LCR = 0x00000083; // 8 bits, no Parity, 1 Stop bit
>> > UART0_DLL = 0x0000000C; // 4800 Baud Rate @ 60MHz VPB Clock
>> > UART0_DLM = 0x00000003; // 4800 Baud Rate @ 60MHz VPB Clock
>> > UART0_LCR = 0x00000003; // DLAB = 0
>> > UART0_FCR = 0x00000007; // Enable and reset TX and RX FIFO.
>> >
>> > while(1)
>> > {
>> > recv_byte = getchar();
>> > dec2bin(recv_byte, binary);
>> > }
>> >
>> > int getchar (void)
>> > {
>> > while (!(UART0_LSR & 0x01)); // Does not execute beyond this point.
>> > return (UART0_RBR);
>> > }
>> >
>> >
>> >
>> > Thanks,
>> > Priyank
>> >
>>
>>
>>
--- In l..., Priyank Maiya wrote:
>
> Hi,
> Could anyone please help me with this.
>
> Thanks,
> Priyank

If you are using the DB9 connector (assuming it has one) then you are dealing with RS232 and that should talk to a PC quite well with a straight-through cable

Does your other gadget also use RS232? Does it also talk to a PC with a straight-through cable? If so, you need a null modem cable to make the connection.

All you really need to do is swap pins 2 & 3 from end to end so that Tx on one end connects to Rx on the other.

Your code looks fine.

Richard