Arduino Mega 2560 receives 0xFFs from Fingerprint Module 5V TTL

i am interfacing Fingerprint 5v TTL

i have done all the work successfully only when i start receiving the raw image data over serial port the Arduino should receive 19200 Bytes but around the 11000 byte the Arduino keeps receiving 0xFF and only 0xFF up for the rest of the loop

the for loop to get data from Fingerprint module:

for (a=0;a<4096;a++)
{
for(int c=0;c<16;c++)
{
rawimageresponse = Serial1.read(),HEX;
Serial.print(rawimageresponse, HEX);
}
Serial.println();

}

keeping in mind that the Fingerprint is functioning perfectly while used with a USB to Serial adaptor using the sdk_example program

Thanks, Yehia

You have to wait for Serial1.available(). If you do a read when data is unavailable you get -1 and if you store that in an unsigned char you get 0xFF.

   for (a=0;a<4096;a++)
    {
      for(int c=0;c<16;c++)
      {
       while (!Serial1.available()) ;  // Wait until a character is available
        rawimageresponse = Serial1.read(),HEX;
        Serial.print(rawimageresponse, HEX);
      }
        Serial.println(); 
    }

i did what you just said but the loop seems to freeze after printing 8992 bytes out of the 19200 and it is stuck in the for loop !

while the usb to serial gets the whole 19200 Bytes

Is Serial running at a much faster rate than Serial1? If not you could be falling behind and running out of buffer space.

Serial.print(rawimageresponse, HEX); displays a byte as two characters. In order not to fall behind the Serial output will have to run at least twice as fast a Serial1 input.

do you mean the baud rate? initially i set both to 115400 and then tried until 9600 but same problem .

i still can't see the problem !

For debugging , just display the number of the set of 16 bytes received, don't Serial.print.
This will eliminate the Serial input buffer question.

i.e.
comment out
// Serial.print(rawimageresponse, HEX);

change
Serial.println();
to
Serial.print(a);Serial.println()

For real

while (!Serial1.available()) ;

should be something more robust perhaps including a delay and a max count to wait for data

still no new it stops after printing about 8900 bytes and it is stuck in the loop

what makes me crazy is that the usb to serial adapter just works fine delivering the whole 19200 Bytes

yehia:
i did what you just said but the loop seems to freeze after printing 8992 bytes out of the 19200 and it is stuck in the for loop !

In that case you need to post your code.