Page 1 of 2

UART problem

Posted: Tue Oct 05, 2004 3:57 am
by harsh
Hi,

I am writing serial driver using polling mechanism.
UART type is 16550A

uart_init ...

0x80 Value is written into LCR Register
OxOC Value is send to Divisor (Least Significant Byte) Register
0x00 Value is send to Divisor (Most Significant Byte) Register
0x0C to LCR register (8n1)
0x00 to IER register
0x87 to FCR register
0x0B to MCR register

UART read

LSR value Displays--- (0x07)
checking for LSR register & 0x01 == 0x01
Read the data from the buffer

UART write

LSR value Displays--- (0x07)
checking for LSR register & 0x20 != 0x020
waiting until LSR THRE bit becomes high (control keep on checking )
write the data to the port

Problem:

LSR register value is not changed at any stage of my code.It returns always 0x07.

would you please tell me what will be the problem with this code?


Thanks & Best regards,
harsha

Re:UART problem

Posted: Tue Oct 05, 2004 11:06 am
by Dreamsmith
harsh wrote:0x0C to LCR register (8n1)
Err, 0x03 would be the correct value for 8N1. You're setting 5O1.5.
harsh wrote:LSR register value is not changed at any stage of my code.It returns always 0x07.
Constant parity and overrun errors? That sounds right, given that the other end is probably sending 1 start bit, 8 data bits, and 1 stop bit (10 bits total) whereas your expecting 1 start bit, 5 data bits, 1 odd parity bit, and 1.5 stop bits (8.5 bits total). Anything you get should cause an overrun error. Parity ought to be right half the time on average, but depending on the data stream, who knows...

Re:UART problem

Posted: Tue Oct 05, 2004 6:36 pm
by harsha110
>0x0C to LCR register (8n1)

I have changed the UART init by

0x03 to LCR register (8n1)

still I am facing the same problem that LSR register value
return by 0x07.
so I am not able to send any data since THRE bit in LSR is
not setting in UART write.

plz help me to solve this problem

Re:UART problem

Posted: Wed Oct 06, 2004 1:11 am
by Dreamsmith
I don't see any other obvious problems -- I don't do anything more than that to initialize the UART in my own OS code (I use a null modem for debugging).

Code: Select all

   outportb(0x3F8 + IER, 0x00); // No interrupts
   outportb(0x3F8 + LCR, 0x80); // DLAB
   outportb(0x3F8 + DL0, 0x01); // 115.200 kbps
   outportb(0x3F8 + DL1, 0x00);
   outportb(0x3F8 + LCR, 0x03); // 8N1
   outportb(0x3F8 + FCR, 0x00); // FIFO's off
   outportb(0x3F8 + MCR, 0x03); // DTR + RTS
That's all I do, and it works fine. Only differences between this and what you've posted is I don't use the FIFOs (I frequently test on hardware with the 16450), and I don't enable the auxiliary output 2 in the MCR. It ought to work...

Perhaps you have a typo somewhere, or something else is interfering? Are you sure the serial port is good? (I beat my head against a box for a couple of hours once before I discovered my code was fine, the computer's serial port was broken.)

Re:UART problem

Posted: Wed Oct 06, 2004 2:02 am
by harsha110
Thanks for ur response.

I will give you more info about the behaviour

I have serial application which will send/receive data from
modem

Initially it is calling UART read method
In UART read method
I am checking
while ((LSR & 0x01) == 0x01) && (10 times)
printf(data) // Reading from port

it displays "0 0 0 0 0 0 ....times"
LSR value is 0x07 for all times

then if i type any char it calls writea method
& control is checking for LSR THRE bit contineously
LSR value is 0x07 for all times

If I ignore the check (LSR & 0x20 != 0x20) in write method
& Type A
it sends &
Read method calls
while ((LSR & 0x01) == 0x01) && (10 times)
printf(data) // Reading from port

it displays "A A A A A ....times"

Type T
it sends &
Read method calls

it displays "T T T T ....times"
....

I feel serial port is working properly.

Do you have any idea how will control LSR register?
is this problem caused because of no interrupt?

Re:UART problem

Posted: Wed Oct 06, 2004 3:39 am
by crc
is this problem caused because of no interrupt?
Interrupts aren't neccessary for using a serial port, so that shouldn't be a problem. I have a version of my OS kernel that uses the serial port for console I/O, and it didn't have any interrupt support until recently. Here's a link to a simple polled serial port example; it helped me quite a bit while I was getting mine up and running.

http://www.beyondlogic.org/serial/termpoll.c

Re:UART problem

Posted: Wed Oct 06, 2004 8:16 pm
by harsha110
I tested with termpoll application

I think it gives same behaviour like

when I type char 'A'

it prints contineously AAAAAAAAAAA...

when I type char 'T'

it prints contineously TTTTTTTT...

when I type char 'Z'

it prints contineously ZZZZZZZZ...

LSR DR bit is not setting to 0 at any case.
it looks always LSR return 7

Re:UART problem

Posted: Wed Oct 06, 2004 9:54 pm
by mystran
You are reading the same thing several times. You should either check if new data is available before reading it, or use interrupts.

Re:UART problem

Posted: Wed Oct 06, 2004 10:49 pm
by harsha110
pla check this
UART type is 16550A

uart_init ...

0x80 Value is written into LCR Register
OxOC Value is send to Divisor (Least Significant Byte) Register
0x00 Value is send to Divisor (Most Significant Byte) Register
0x03 to LCR register (8n1)
0x00 to IER register
0x07 to FCR register
0x0B to MCR register

UART read

IER value display -- (0x07) //Just checked
0x00 to IER register ////Just checked
IER value display -- (0x01)//Just checked

LSR value Displays--- (0x07)
checking for LSR register & 0x01 == 0x01
Read the data from the buffer

UART write

LSR value Displays--- (0x07)
checking for LSR register & 0x20 != 0x020
waiting until LSR THRE bit becomes high (control keep on checking )
write the data to the port

I tested modem with win32 serial driver it works fine.
so no problem with modem or serial port
but my code is not working.

Actually IER register should return 0x00 for this setting & LSR should vary once we read the data from the port.

in my case both are not happening...

Re:UART problem

Posted: Wed Oct 06, 2004 11:48 pm
by Brendan
Hi,

A dumb question, but are you sure you actually are reading the LSR? It wouldn't be the first time a programmer tried to use the wrong IO port :-)


Cheers,

Brendan

Re:UART problem

Posted: Thu Oct 07, 2004 12:26 am
by harsha110
Checked for port address & LSR

COM2 -> 0x2F8
LSR_REG -> 5

& I am doing like (COM2 + LSR_REG)

Re:UART problem

Posted: Thu Oct 07, 2004 6:00 am
by crc
I am doing like (COM2 + LSR_REG)
That should be ok. Your values are correct, at least for LSR and COM2.

If I ignore the check (LSR & 0x20 != 0x20) in write method
I'm not sure; would changing this to [tt]((LSR & 0x20) != 0x20)[/tt] make a difference? (I ask this because I don't use C very often)

Could you post the actual code? That would make it easier for us to help figure out what's wrong.

Re:UART problem

Posted: Thu Oct 07, 2004 9:42 am
by mystran
Indeed, == and != are just before & in the precedence order. (I actually checked this).

Re:UART problem

Posted: Fri Oct 08, 2004 1:32 am
by harsha110
u can refer this code
http://www.beyondlogic.org/serial/termpoll.c

and the behaviour also i explained in my previous mail.

For ur info...
I am using wireless modem for test

Re:UART problem

Posted: Fri Oct 08, 2004 5:35 am
by crc
I'm quite familiar with the termpoll.c example. You've mentioned some checks that you do. What is the actual code? The checks in termpoll.c don't parallel the examples you've shown. So exactly what are you checking and how are you checking it? I've tested termpoll.c and it works fine on my hardware.

I also wrote two polled serial port drivers that work, but I don't think they'll help you very much. (One is written in Forth, the other is written in assembly). If you want to see them, let me know. I'll try to translate my driver to C; maybe it'll be a help.