UART problem
UART problem
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
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
Err, 0x03 would be the correct value for 8N1. You're setting 5O1.5.harsh wrote:0x0C to LCR register (8n1)
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...harsh wrote:LSR register value is not changed at any stage of my code.It returns always 0x07.
Re:UART problem
>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
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
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).
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.)
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
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
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?
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
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.is this problem caused because of no interrupt?
http://www.beyondlogic.org/serial/termpoll.c
Re:UART problem
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
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
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
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...
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
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
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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re:UART problem
Checked for port address & LSR
COM2 -> 0x2F8
LSR_REG -> 5
& I am doing like (COM2 + LSR_REG)
COM2 -> 0x2F8
LSR_REG -> 5
& I am doing like (COM2 + LSR_REG)
Re:UART problem
That should be ok. Your values are correct, at least for LSR and COM2.I am doing like (COM2 + LSR_REG)
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)If I ignore the check (LSR & 0x20 != 0x20) in write method
Could you post the actual code? That would make it easier for us to help figure out what's wrong.
Re:UART problem
Indeed, == and != are just before & in the precedence order. (I actually checked this).
Re:UART problem
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
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
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.
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.