Problem in LSR

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
udhayakumar

Problem in LSR

Post by udhayakumar »

Hi all,

I am writing serial driver.

Hope write method id working.

How i will know with only init method led in the modem is ot glowing.

And even while writing also i am checking MSR and LSR value.

I am checking MSR with 0x10 and LSR with 0x20.

It is going through correctly.

But after this i am setting MSR 0x09 and read the LSR value.

And checked with 0x20.

But here it fails. I am not able to read any character.

Please help me to solve this problem

Note: I am not using Inetrrupts.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Problem in LSR

Post by Brendan »

Hi,

Let me see...

A Possible Translation:
I am writing a serial driver.

I hope the code to send data is working.

How will I know with only the initializing code? The LED in the modem is not glowing.

And even while I'm writing I'm checking MSR and LSR values. [not sure what is being written here, possibilities include writing the serial device driver, writing data to an IO port or sending bytes to the serial port]

I am checking the MSR which is 0x10 and LSR which is 0x20. [That would imply CTS (or Clear To Send) is active, and the THR (Transmitter Holding Register) is empty - ie. the device is ready for data to be sent to it]

It is going through correctly. [I'm assuming this means that data is being sent from the computer to the device via the serial port correctly]

But after this I am setting MSR to 0x09 and reading the LSR value. [The MSR (Modem Status Register) is read-only. If you mean the MCR (Modem Control Register) then you'd be activating DTR (Data Terminal Ready) and enabling interrupts, while de-activating RTS (Ready To Send) and disabling loopback testing.]

And the LSR reads 0x20. [The THR (Transmitter Holding Register) is still empty]

But here it fails. I am not able to read any data from the serial port.

Please help me to solve this problem

Note: I am not using Interrupts.
Sorry if my translation sounds too condescending - I'm just trying to figure out what the problem might be.

Some questions that might help narrow the problem down a bit:

A) How close are my guesses above?

B) Are you trying to write to the MSR, or are you accidentally enabling interrupts in the MCR?

C) What is connected to your serial port, e.g. mouse, modem, serial transfer cable (laplink or NULL modem)?


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.
Uthaman

Re:Problem in LSR

Post by Uthaman »

Hi,

I am also facing the same problem.

In my case PCMCIA Card is connected at Serial Port (which will acts like a modem - Type II card)

I am also not using Interrupts.

Steps Followed in Init method:
==================================

1.0x80 Value is written into LCR Register

2.OxOC Value is send to Divisor (Least Significant Byte) Register

3.0x00 Value is send to Divisor (Most Significant Byte) Register

Above steps i have used for setting BAUD Value.

4.I have set value 0x03 in LCR. (Whcih menas 8bit-No Parity - 1 Stop bit)

Steps followed in Write method.
=================================

1.IN MCR i have set 0x0A. That is enabling RTS and Out2.

2.Get the Value in MSR and checked bit 4 is enabled or not.

ie Checking CTS Value in MSR.

3.Get the Value in LSR and checked bit 5 is enabled or not.

ie Checking THR is empty

4.Sending Data through THR.

Steps followed in Read method
===============================

1.IN MCR i have set 0x09 that is enabling DTR and Out2.

2.Get the Value in MSR and checked bit 5 is enabled or not.

ie Checking Data set ready.

(Upto this control is going smoothly)

3.Get the Value in LSR and checked bit 1 is enabled or not.

ie Checking Data set

4.Read the Value RHB.

Control is not coming out from Step 3.

It is always giving 0x60 as value in LSR.

I dont know whether my read method is wrong or my write method is wrong.

Please help me to solve this problem.

Note:

PCMCIA Card is connected at COM2
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Problem in LSR

Post by Brendan »

Hi,
Uthaman wrote: I am also not using Interrupts.

Steps followed in Write method.
=================================

1.IN MCR i have set 0x0A. That is enabling RTS and Out2.
User output line #2 is used to enable interrupts! Also user output #1 should be preserved as it may be connected to some strange things (e.g. it could change the base frequency of the clock used for BAUD rate to be compatible with MIDI):

Code: Select all

   mov dx,MCR
   mov al,dx
   and al,0x04
   or al,0x02
   out dx,al
Uthaman wrote: 2.Get the Value in MSR and checked bit 4 is enabled or not.

ie Checking CTS Value in MSR.

3.Get the Value in LSR and checked bit 5 is enabled or not.

ie Checking THR is empty

4.Sending Data through THR.

Steps followed in Read method
===============================

1.IN MCR i have set 0x09 that is enabling DTR and Out2.
See above with regard to user output lines..
Uthaman wrote: 2.Get the Value in MSR and checked bit 5 is enabled or not.

ie Checking Data set ready.

(Upto this control is going smoothly)

3.Get the Value in LSR and checked bit 1 is enabled or not.

ie Checking Data set

4.Read the Value RHB.

Control is not coming out from Step 3.
Ok, what do you send to the device, and what is it expecting (I don't know much abut PCMIA)? Can you use something like HyperTerminal (Windows), or Telix (DOS) to get the device to send data to the computer?


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.
Uthaman

Re:Problem in LSR

Post by Uthaman »

Hi,

I have pasted my code .

My UART is 16550A. I am using COM2.

Now i am using Modem instead of PCMCIA.

Still i am finding the same problem.

#define UART_BASEADDR 0x2F8 // the base address of the UART
#define UART_BAUDRATE 0x0C //the divisor value (e.g. 12 for 9600 baud)
#define UART_LCRVAL 0x1F //the value to be written to the LCR (e.g.0x1b for 8N1)
#define UART_FCRVAL 0x87

void UART_INIT()
{
outportb(UART_BASEADDR+3,0x80);
outportb(UART_BASEADDR,0x0C);
outportb(UART_BASEADDR + 1,0x00);
outportb(UART_BASEADDR+3,0x03);
outportb(UART_BASEADDR+4,0x00);
}

void ReadWrite()
{

   char key[4];
   int ret;
   int iInc = 0;
   int i = 0;
   strcpy(key,"ATZ");

   /*****Write ****/

   // Setting MCR Value
   ret = inportb(UART_BASEADDR+4);
   ret = ret & 0x04;
   ret = ret | 0x02;
   ret = outportb(UART_BASEADDR+4,ret);

   // Reading MSR Value
   ret = 0;
   ret = inportb(UART_BASEADDR+6);
   ret = ret & 0x10;

   //Checking THRE
   while(ret != 0x10)
   {
      ret = 0;
      ret = inportb(UART_BASEADDR+6);
      ret = ret & 0x10;
   }

   //Sending ATZ to modem
   while (1)
   {
      // Reading LSR
      ret = 0;
      ret = inportb(UART_BASEADDR+5);
      ret = ret & 0x20;
      
      //Checking CTS
      while(ret != 0x20)
      {
          ret = 0;
          ret = inportb(UART_BASEADDR+5);
          ret = ret & 0x20;
      }
      
      // Send Charcter
      outportb(UART_BASEADDR,key[iInc++]);
      
      // Stop After ATZ
      if(iInc == 3)
         break;
   }

   /*****Read ****/
   
   // Setting MCR Value
   ret = inportb(UART_BASEADDR+4);
   ret = ret & 0x04;
   ret = ret | 0x01;
   ret = outportb(UART_BASEADDR+4,ret);

   // Reading MSR Value
   ret = 0;
   ret = inportb(UART_BASEADDR+6);
   ret = ret & 0x30;

   // Checking Data set ready
   while(ret != 0x30)
   {
      ret = 0;
      ret = inportb(UART_BASEADDR+6);
      ret = ret & 0x30;
   }
   
   // Reading character -- Just reading 2 characters. ATZ will give OK
   iInc = 0;
   while(1)
   {
      ret = 0;
      ret = inportb(UART_BASEADDR+6);
      ret = ret & 0x01;

      while(ret != 0x01)
      {
          ret = 0;
          ret = inportb(UART_BASEADDR+6);
          ret = ret & 0x01;
      }
      
      ret = 0;
      ret = inportb(UART_BASEADDR);
      printf("%c\t",ret);
      iInc++;
      if (iInc > 1)
      break;
   }
}

int main(int argc, char **argv)
{
   UART_INIT();
   ReadWrite()
}
Uthaman

Re:Problem in LSR

Post by Uthaman »

Hi all,

I modified my code and attaching the same with this.

Now when i am reading i am getting ATZ instead of OK.

Please help me how to solve this problem.

Regards

Uthaman
Uthaman

Re:Problem in LSR

Post by Uthaman »

Hi all,

While reading from LSR i got 0x60 Value.

Can any one help me to solve this problem?

Regards

Uthaman
Post Reply