|
|
View previous topic :: View next topic |
Author |
Message |
andys
Joined: 23 Oct 2006 Posts: 175
|
problem with ublox gps |
Posted: Sun Jun 01, 2014 4:58 pm |
|
|
I am facing a little strange problem. I am using a ublox gps and when I connect it to the pc(via microcontroller) I get strange characters instead of information. I am using 9600 baud rate is this the problem ?
I am using the driver at :
http://www.ccsinfo.com/forum/viewtopic.php?t=45827&highlight=
to parse the information of the gps module.
The main which I used is:
Code: |
#include <33fj128GP802.h>
#FUSES NOPROTECT
#FUSES NOIESO
#FUSES FRC
#FUSES NOWDT
#use delay(clock=7.37MHz) //default frequency for RC
#include "GPS.c"
#PIN_SELECT U1TX=PIN_B14
#PIN_SELECT U1RX=PIN_B15
#USE RS232(UART1,ERRORS,BAUD=9600,STREAM=COM_A)
#PIN_SELECT U2TX=PIN_B2
#PIN_SELECT U2RX=PIN_B3
#USE RS232(UART2,ERRORS,BAUD=9600,STREAM=COM_B)
char GPSData[128];
unsigned int8 GPSDataPtr=0;
char c;
int8 GPSDataReady = FALSE;
#INT_RDA
void RDA_isr(void)
{
char c;
unsigned int8 GPSDataPtr=0;
c=getc(COM_B);
switch (c)
{
case '$':
GPSDataPtr = 0;
break;
case '\n':
GPSDataReady = TRUE;
break;
}
GPSData[GPSDataPtr++ & 0x7F] = c;
}
void main()
{
//char GPSData[128];
//unsigned int8 GPSDataPtr=0;
//char c;
//int8 GPSDataReady = FALSE;
int8 GPSmsgCount = 0;
GPRMCInfo MyGPRMCInfo;
//enable_interrupts(GLOBAL);
//enable_interrupt(INT_RDA);
while(1)
{
RDA_isr();
fprintf(COM_A,"HELLO\n");
fprintf(COM_A,"GPSDataReady:%d\n",GPSDataReady);
//}
if (GPSDataReady)
{
GPRMC_decode(GPSData, &MyGPRMCInfo);
if (MyGPRMCInfo.Valid == 'A')
{
fprintf(COM_A,"\n\rTime: %d:%d:%d\n\r", MyGPRMCInfo.DT.Hour, MyGPRMCInfo.DT.Minute, MyGPRMCInfo.DT.Second);
fprintf(COM_A,"Date: %d/%d/%d\n\r", MyGPRMCInfo.DT.Day, MyGPRMCInfo.DT.Month, MyGPRMCInfo.DT.Year);
fprintf(COM_A,"Latitude: %f %c\n\r", MyGPRMCInfo.Latitude, MyGPRMCInfo.N_S);
fprintf(COM_A,"Longitude: %f %c\n\r", MyGPRMCInfo.Longitude, MyGPRMCInfo.E_W);
fprintf(COM_A,"Speed: %f knots\n\r", MyGPRMCInfo.Speed);
fprintf(COM_A,"Data saved!\n\r");
}
GPSDataReady = FALSE;
}
}
}
|
I test the code without call the function of the gps and is ok, so the microcontroller send the right data to pc.
Is anyone who can help me to find the problem?? |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
problem with ublox gps |
Posted: Mon Jun 02, 2014 12:33 am |
|
|
any suggestions? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Mon Jun 02, 2014 1:21 am |
|
|
GPSDataPtr in the ISR, should be declared as static. It shouldn't get corrupted (the compiler will normally treat variables inside an ISR as static, but 'be safe').
The code is 'wrong'. You are calling the ISR from the main code, instead of letting the interrupt call it. This will hang the code waiting for data to arrive. Yetch...
You then have the same variable 'GPSDataPtr', declared locally in the ISR, and globally. The ISR will use the local copy. The original example, only has the variable declared once.
Then the printouts will take dozens of mSec to execute, meanwhile more data will be arriving, and being lost, since you will not be calling the 'ISR'. This is why it should be called by the interrupt....
Then the parser, expects _strings_ which means a null terminator, but you are not writing one when the line feed is found.
This is a fault in the demo code, as are a couple of other minor things:
Code: |
#include <33fj128GP802.h>
#FUSES NOPROTECT
#FUSES NOIESO
#FUSES FRC
#FUSES NOWDT
#use delay(clock=7.37MHz) //default frequency for RC
#include "GPS.c"
#PIN_SELECT U1TX=PIN_B14
#PIN_SELECT U1RX=PIN_B15
#USE RS232(UART1,ERRORS,BAUD=9600,STREAM=PC)
#PIN_SELECT U2TX=PIN_B2
#PIN_SELECT U2RX=PIN_B3
#USE RS232(UART2,ERRORS,BAUD=9600,STREAM=GPS)
char GPSData[128];
int1 GPSDataReady = FALSE;
//you are using COM1 for the PC display, hence this has to be RDA2
#INT_RDA2
void RDA_isr(void)
{
static unsigned int8 GPSDataPtr=0;
char c;
//it is generally better to declare variables 'in routine' where they do not
//want/need to be global
c = fgetc(GPS); //must use streams
switch (c)
{
case '$':
GPSDataPtr = 0;
break;
case '\n':
GPSData[0] = `\0';
GPSDataPtr = 0;
GPSDataReady = TRUE;
//null terminate the string. Avoids possible problems
//with the library functions.
break;
default:
GPSData[GPSDataPtr++ & 0x7F] = c
break;
}
}
void main(void)
{
GPRMCInfo MyGPRMCInfo;
enable_interrupts(INTR_GLOBAL);
enable_interrupt(INT_RDA2);
while(TRUE)
{
if (GPSDataReady)
{
GPSDataReady = FALSE; //generally reset flags ASAP
GPRMC_decode(GPSData, &MyGPRMCInfo);
if (MyGPRMCInfo.Valid == 'A')
{
fprintf(PC,"\n\rTime: %d:%d:%d\n\r", MyGPRMCInfo.DT.Hour, MyGPRMCInfo.DT.Minute, MyGPRMCInfo.DT.Second);
fprintf(PC,"Date: %d/%d/%d\n\r", MyGPRMCInfo.DT.Day, MyGPRMCInfo.DT.Month, MyGPRMCInfo.DT.Year);
fprintf(PC,"Latitude: %f %c\n\r", MyGPRMCInfo.Latitude, MyGPRMCInfo.N_S);
fprintf(PC,"Longitude: %f %c\n\r", MyGPRMCInfo.Longitude, MyGPRMCInfo.E_W);
fprintf(PC,"Speed: %f knots\n\r", MyGPRMCInfo.Speed);
fprintf(PC,"Data saved!\n\r");
}
}
}
}
|
As a further comment, check what data rate the module is programmed for. Some do arrive set for faster rates than 9600bps, and some are not set to return standard NMEA strings. Ones programmed for the Arducopter are set to return a compressed data format at much higher rates, which the code won't decode. Check this before going any further. They are reprogrammable to 'standard'.
Then the original code has the printout, just for debugging. Do you really want to print all the data every time?. You may not find there is time to send so much between messages.... |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
problem with ublox gps |
Posted: Mon Jun 02, 2014 7:23 am |
|
|
Ttelmah thanks for the reply.
I did the changes to the code and now I have a different problem. When I connect the gps module to the pc I don’t receive any data.
I checked the accepted baud rate of the module and I saw that the baud rate is 9600 as you can see from the attachment.
http://obrazki.elektroda.pl/9111903900_1401715323.png
Any other suggestions ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Mon Jun 02, 2014 7:42 am |
|
|
Are you sure you have the unit on the right pins?. There was significant confusion in the original code, with your printout going to COM_A, and the unit being unspecified (you weren't using the stream). Triple check your actual connections. Remember unit TX to PIC RX etc.. |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
problem with ublox gps |
Posted: Mon Jun 02, 2014 11:00 am |
|
|
You are right Ttelmah, there was a problem with the tx/rx pins and I corrected it.
Another problem is the statement
Code: | if (MyGPRMCInfo.Valid == 'A') |
with this condition I don’t get any data.
If I remove this condition I will get the following output.
Code: |
Time: 88:-122:104
Date: -60/72/-27
Latituþ
Time: 88:-122:104
Date: -60/72/-27
Latituþ
Time: 88:-122:104
Date: -60/72/-27
Latituþ
Time: 88:-122:104
Date: -60/72/-27
Latituþ
Time: 88:-122:104
Date: -60/72/-27
Latituþ
Time: 88:-122:104
Date: -60/72/-27
Latitude: 0.00 a
Longitude: 0.00 Ì
Speed: -92233720368547758.08 knots
Data saved!
Time: 88:-122:104
Date: -60/72/-27
Latituþ
Time: 88:-122:104
Date: -60/72/-27
Latituþ
Time: 88:-122:104
Date: -60/72/-27
Latituþ
Time: 88:-122:104
Date: -60/72/-27
Latituþ
Time: 88:-122:104
Date: -60/72/-27
Latituþ
Time: 88:-122:104
Date: -60/72/-27
Latitude: 0.00 a
Longitude: 0.00 Ì
Speed: -92233720368547758.08 knots
Data saved!
|
From what you can see there are a lot of problems with the output. I can’t understand what are the reasons!!!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Mon Jun 02, 2014 12:34 pm |
|
|
That's easily fixed.
I didn't bother to copy the '$' into the output string (I'd consider it a waste of space to do so), but the parser requires this to be copied. Modify my ISR to:
Code: |
//you are using COM1 for the PC display, hence this has to be RDA2
#INT_RDA2
void RDA_isr(void)
{
static unsigned int8 GPSDataPtr=0;
char c;
//it is generally better to declare variables 'in routine' where they do not
//want/need to be global
c = fgetc(GPS); //must use streams
switch (c)
{
case '$':
GPSDataPtr = 1;
GPSData[0] = `$';
break;
case '\n':
GPSData[GPSDataPtr] = `\0';
GPSDataPtr = 0;
GPSDataReady = TRUE;
//null terminate the string. Avoids possible problems
//with the library functions.
break;
default:
GPSData[GPSDataPtr++ & 0x7F] = c
break;
}
}
|
and it should find the data if it is valid. |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
problem with ublox gps |
Posted: Wed Jun 04, 2014 12:41 pm |
|
|
unfortunately the problem is still here.
exactly the same problem.
If i remove the condition Code: | if (MyGPRMCInfo.Valid == 'A') | i can get some values (wrong values). with this condition i can receive anything.
any ideas what is going wrong ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Wed Jun 04, 2014 12:55 pm |
|
|
'wrong values'...
could it be a UART speed problem ?
Looks like you've got the pIC as an RC osc...it might be off a tad ????
hth
jay |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Wed Jun 04, 2014 1:02 pm |
|
|
Are you doing the testing indoors? Many GPS receivers lack the sensitivity to run properly indoors, thus the reason why you aren't getting a valid fix. |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
problem with ublox gps |
Posted: Wed Jun 04, 2014 1:06 pm |
|
|
I have already think about this possibility .
when i use a simple "fprintf hello" (without use the GPS) i can see the data.
Is it possible the uart speed to be ok for a simple "print hello" and to have a problem with the use of GPS ????
What do you mean by it might be off a tad ???? |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
problem with ublox gps |
Posted: Wed Jun 04, 2014 1:07 pm |
|
|
The GPS module is outdoor . |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed Jun 04, 2014 1:26 pm |
|
|
Hi andys,
Can you tell us which 'Ublox GPS' you are using? I'd like to take a look at the datasheet for this module. What is the supply voltage for your PIC? What is the supply voltage for your GPS?
I'm not sure it's been established that the PIC is actually receiving *correct* data from the GPS. For now, rather than sending possibly bogus data to the GPRMC parser, why not just print out the received string and see what you've got? Is it valid? The GPS datasheet should give an example of a valid GPRMC sentence for comparison.....
Do you actually know what the GPS is sending? Most GPS modules will send multiple NMEA sentences in quick succession every second. Your code is really only interested in the GPRMC message, so any other messages are going to just require more work on the part of your code, and tighter timing..... You could program the GPS module to only send the GPRMC message, or you could add code (a 'state machine') to exclude any data except the GPRMC data.....
The 'A' is important because it's the 'flag' in the received data stream that says the sentence that contains it is actual GPS derived position data, ie. the GPS module has a fix. My guess is that you aren't actaully receiving any 'good' data at all. My hunch is that you've got a level problem, or a inversion problem, or something like that. The datasheet will tell the story for us!
You seem to be very close to success here, so please don't get too discouraged!
John |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
problem with ublox gps |
Posted: Wed Jun 04, 2014 4:15 pm |
|
|
|
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed Jun 04, 2014 5:51 pm |
|
|
Hi,
The documents you posted are for the bare Ublox GPS modules. To run, they need additional support circuitry, including an antenna. Did you make your own board to do this, or did you buy one? If you made your own board, post a schematic. If you bought a board, then post a link. I'm trying (mightily) to verify that your 'GPS module' is communicating with the PIC using 'TTL serial', and that you don't have a hardware compatibility problem. You aren't making this quest a particularly easy task.....
You posted a GPRMC message with a recent date, so I assume your actually read that from the Ublox GPS module? Is that true? If so, please describe in detail how you did that. Was the GPS module connected directly to your PC? If so, how? Or, was the GPS module connected to your PIC, which was then connected to your PC? If so, did you just print the received string as I suggested without sending it to the parser?
At this stage, details are *really* important, so please be very complete, and very precise!
I don't think the extra ',' at the end of the sentence is relevant to your problem. The parser doesn't care, and doesn't even bother to attempt to read anything beyond the date anyway. Certain NMEA versions had fewer or more fields in the GPRMC message, but I don't believe it's an issue for you....
One thing that caught my eye was an apparent typo in your int_rda2 interrupt handler. Check this code:
and this one:
Code: |
GPSData[GPSDataPtr] = `\0';
|
The opening single-quote mark in each of these lines seems incorrect. I would think the compiler would catch this, but please double check it! Note the difference between ` and '!
John |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|