Problem porting sketches from Duemilanove to Mega

Hi,

I've reached the memory limits of the Duemilanove so have recently ported a GPS sketch to a Mega2560. The sketch is designed to read GPS data from an external GPS device that's transimitting NMEA sentences at a rate of 4800 b/s via a Max232 converter.

The only software differences between the original sketch and the one now running on the mega is that the original was using the NewSoftSerial library to read the data over ports 2 and three and the new one uses Serial1 on pins 18 and 19 of the Mega. (I've tried serial 2 and 3 too)

Now here's the problem - the orignal sketch indicated that about 95% of NMEA senetences are valid, for my application this was an acceptable figure. However, on the Mega version only about 20% are VALID.

For those not familar with NMEA sentences, the last two characters are checkdigits formed by XORing all the previous bytes in the record, this is what I've been using to confirm the validity of each sentence.

My skteches and library are too large to be included here, does anyone have any suggestions as to what might be wrong?

Finally, I've tried displaying the NMEA records as they arrive, and they all look to the untrained eye to be ok (no weird characters etc, nothing obviously truncated or missing).

just an idea, but does it make any difference how frequently data is read from the GPS? I've just notices that each time the GPS is read between 50 and 150 characters are processed. Could there be some buffering issues here? should I be reading the GPS signal more often and takeing fewer bytes each read?

Regards

For those not familar with NMEA sentences, the last two characters are checkdigits formed by XORing all the previous bytes in the record, this is what I've been using to confirm the validity of each sentence.

Finally, I've tried displaying the NMEA records as they arrive, and they all look to the untrained eye to be ok (no weird characters etc, nothing obviously truncated or missing).

This suggests, but is by no means definite, that there is something different in the way that you calculate the checksum and the way that the GPS calculated the checksum.

Yup - that's it.

Reading from the serial port more frequently so that no more that 20-30 characters are read each time seems to improve the accuracy of the data. Still not sure why it's different with the Mega, but at least the issue is solved.

I've just notices that each time the GPS is read between 50 and 150 characters are processed.

With a 128 character serial buffer, processing 150 characters from the buffer isn't possible.

Yup - you're right PaulS - I was mis-counting. The basic problem was that I reading from the buffer to infrequently, I guess a character must have been droped here and there. I've upped the frequency and now it works fine.

Thanks for your help