Parallax GPS Module - reading bytes problem?
Hi guys... first of all I would like to mention that I am using a PIC 18f4550 microcontroller, and I am programming in C with the C18 compiler. I allready tried to find a solution in many different ways, but since my GPS module is from Parallax I hope to find some users who have experience in how this things works.
The Problem:
I'm having problems reading my Parallax GPS module.·I am using the Smart Mode, which sort of works right. What happens is that I now open a USART connection and send a command byte .. after that I open a new connection to receive the 5 corresponding bytes·with data I requested. This all works fine, since I analyzed the bytes with an ossiloscope and received the exact coordinates of my house (which means it works). However when I write a receive loop for my PIC18f4550 microcontroller, I can't get the data right. The first byte I received has the same data from my ossiloscope analysis, but bytes 2 to 5 are different from what I analyzed on the scope.
This has probably something to do with reading multiple bytes out of the USART buffer. Can somebody help me with this?
·
The Documents:
- Parallax GPS Datasheet (http://www.parallax.com/Portals/0/Downloads/docs/prod/acc/GPSManualV1.1.pdf)
- PIC18F4550 Datasheet (http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1335&dDocName=en010300)
- C18 Libraries (page 70 for USART)·(http://kevin.org/frc/C18_libraries.pdf)
The Code:
The Problem:
I'm having problems reading my Parallax GPS module.·I am using the Smart Mode, which sort of works right. What happens is that I now open a USART connection and send a command byte .. after that I open a new connection to receive the 5 corresponding bytes·with data I requested. This all works fine, since I analyzed the bytes with an ossiloscope and received the exact coordinates of my house (which means it works). However when I write a receive loop for my PIC18f4550 microcontroller, I can't get the data right. The first byte I received has the same data from my ossiloscope analysis, but bytes 2 to 5 are different from what I analyzed on the scope.
This has probably something to do with reading multiple bytes out of the USART buffer. Can somebody help me with this?
·
The Documents:
- Parallax GPS Datasheet (http://www.parallax.com/Portals/0/Downloads/docs/prod/acc/GPSManualV1.1.pdf)
- PIC18F4550 Datasheet (http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1335&dDocName=en010300)
- C18 Libraries (page 70 for USART)·(http://kevin.org/frc/C18_libraries.pdf)
The Code:
RECEIVE PROCEDURE OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 160 ); //(Baudrate is good ) while(DataRdyUSART()); // If data is not ready, turn LED on {PORTD = 0b00010001;} while(!DataRdyUSART()); //Wait fot data is ready {lat0 = ReadUSART(); //Read data byte 1 lat1 = ReadUSART(); //Read data byte 2 lat2 = ReadUSART(); //Read data byte 3 lat3 = ReadUSART(); //Read data byte 4 lat4 = ReadUSART(); //Read data byte 5 } process_GPS(); //Do something with the data CloseUSART(); //Close connection ---------------------------------------------------------------------------------------------------------------- and I also tried the following method: ---------------------------------------------------------------------------------------------------------------- RECEIVE PROCEDURE OpenUSART (USART_TX_INT_OFF & //Open USART USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 160 ); //(Baudrate is good ) while(DataRdyUSART()); // If data is not ready, turn LED on {PORTD = 0b00010001;} while(!DataRdyUSART()); //Wait fot data is ready {lat0 = ReadUSART(); } //Read data byte 1 while(!DataRdyUSART()); //Wait fot data is ready {lat1 = ReadUSART();} //Read data byte 2 while(!DataRdyUSART()); //Wait fot data is ready {lat2 = ReadUSART();} //Read data byte 3 while(!DataRdyUSART()); //Wait fot data is ready {lat3 = ReadUSART();} //Read data byte 4 while(!DataRdyUSART()); //Wait fot data is ready {lat4 = ReadUSART();} //Read data byte 5 process_GPS(); //Do something with the data CloseUSART(); //Close connection
Comments
Whatever problem you're having has to do with the PIC processor or the I/O libraries or how you've used them and you're not likely to find the expertise or experience here to help you with that. The only place to post questions like this is the Sandbox Forum which is set aside for questions outside the normal range or anything else that doesn't fit the subject matter of the other forums. I suggest you ask in Microchip's support forums.
so you should be able to understand it.
It appears your code is lacking the "!GPS" preamble bytes that must
be present for every command.
You can open the file with any text editor.
regards peter
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support