Hi,
I have interfaced a Garmin GPS to my ARM based microcontroller (LPC 1768) using serial communication. These are the steps am following to read the data
1. Read first 2000 characters from Receiver buffer register and store it in an array. 2. Whenever the count reaches 2000, disable the interrupt and set a flag to 1. 3. When flag is set to 1, parse the characters from the stored array and search for pattern match and when pattern matches extract latitude and longitude. 4. Enable the interrupt again and set the flag to 0 to read the next set of characters.
But with this approach I'm losing the bytes. Pattern doesn't match.
UART initialization includes.
1. Baud rate set to 4800 bps..same as the GPS. 2. Enable Receiver FIFO to receive single character at a time.
I have set the buffer size to a very high value i.e 2000 with an intention that at some point of time, I might receive the data format which i require.
Please help me figure out where am I possibly going wrong?
"Please help me figure out where am I possibly going wrong?"
The main problem? You forgot to post the relevant source code, since you must obviously have a bug in the code somewhere. Or a design goof where you are too slow to pick up data from the UART.
"Enable Receiver FIFO to receive single character at a time."
Note that the FIFO allows the UART to receive _multiple_ characters before you need to empty the UART FIFO. Or for giving the UART multiple bytes to send.
By the way - a GPS often sends about 500 bytes / second, if configured to emit data once/second. The actual amount varies with what strings the GPS is configured to send, how often it is configured to send and number of visible GPS.
But waiting for 2000 characters means that you would normally have several seconds of data in that buffer. So there will be several seconds time difference between first and last line of text in that buffer. That means that you get lag between actual position, and any position your code will extract.
Isn't it better to have the ISR insert data in a ring buffer, and then your main loop picks data from the ring buffer into a line buffer - synchronizing on $ that is start of a line, or \r\n that is end of a line? Then the main loop will never be too far behind in the data processing.
Certainly sounds like your serial reception method is flawed. Why would you need to disable interrupts? Surely you could leave them enabled, and implement some simple line buffering, and queue scheme?
From your description, your parsing scheme is also probably slow/flawed, causing you to miss data.
Thank you very much for the suggestions.
I rewrote my code to include a ring buffer and it works perfectly. I'm able to extract the data without any loss of data.
Thanks again for all the help.