UART dropped chars as a polled device.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UART dropped chars as a polled device.

1,446 Views
M_Grillo
Contributor III
I have an issue using UART0 as polled device. I'm only receiving the first three characters and the last. For example: Terminal sends "12345678", serial_fd receives "1238". I've tried filling a char buffer using 'fgetc', 'fgetline', 'read' and tried several different baud rates with the same result. Below is the function I'm using to read the UART. (MQX 3.3.4 on a m52259demo, modified telnet_to_serial project as base). Queue size is the default 64.
 
int_16 iDrive_getline(uint_16 uiMaxWait, uint_8 ucPtr)
{
 int_16 iRtn=0;
 uint_16 uiTimeOut=0;
 
 while (TRUE)
 { 
   if (fstatus( serial_fd )) //activity on the serial port
   {
     iRtn = fgetc( serial_fd ); //get char on serial port
     if (iRtn==IO_ERROR)
     {
      break;
     }
     ucCharAry[ucPtr++] = iRtn; //fill buffer
     if (iRtn == 0x0A) //"\n"
     {
      iRtn = ((int_16)ucPtr + 1); //Data is good, return char count
      break;
     }
   }
   RTCS_time_delay(1); //1 mSec.
   uiTimeOut++;
   if (uiTimeOut >= uiMaxWait)
   {
     iRtn = SERIAL_TIMEOUT;
     break;
   }
   if (ucPtr >= 64)
   {
     iRtn = SERIAL_BUFOVRN;
     break;
   }
 } //Do 
 return (iRtn);
}
If I enter chars slowly during the loop above I'm fine. If the char stream is received before the loop above is started chars are dropped. Why? Isn't the buffer 64 bytes?
Thanks,
Mark Grillo
2 Replies

294 Views
JuroV
NXP Employee
NXP Employee

Hello.

 

First of all, UART's FIFO is 3 bytes length (MCF52259 ColdFire® Integrated Microcontroller Reference Manual).

So you read all of them (the last one shift register is always rewritten).

Internal buffers in the driver can be used only in interrupt mode, the polled driver itself accesses the registers only when asked (in this case it is in fgetc nested call).

Here you lose all your received data in the 3-bytes buffer:

RTCS_time_delay(1); //1 mSec.

294 Views
M_Grillo
Contributor III
Thanks for the reply JuroV.
 
I misunderstood the MQX driver for the UART. I thought the driver filled a 64 byte queue behind the scenes in polled mode. Also, I was under the assumption that in interrupt mode I need to write an interrupt service routine to fill a char buffer. This is not that case at all. MQX handles everything. I changed the UART0 driver to interrupt, "ittya", and everything works great now!
 
Thanks,
Mark Grillo