|
|
View previous topic :: View next topic |
Author |
Message |
on7nh
Joined: 05 Jun 2006 Posts: 41 Location: Belgium
|
gps Oncore and nmea |
Posted: Sun Oct 08, 2006 1:34 pm |
|
|
Hello folks,
i try to have nmea info from a ONCORE GT module
i send code to de GPS module but nothig returns... Damn
have anybody e idee what i am doing wrong? ( or a working sample?)
i send this commando to the oncore :
#use rs232 ( baud=9600, xmit=PIN_C6, rcv=PIN_C7,stream = GPS, ERRORS ) // XMIT must be assigned to enable hardward USART
printf("@@Ci☺+\r");
set_uart_speed (4800,gps);
printf("$PMOTG,GGA,0001\r"); |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Sun Oct 08, 2006 5:41 pm |
|
|
Most GPS code is like talking to an old gossip. The GPS speaks sentences at its pace and your job is to listen.
Oncore allows the GPS to be polled the code below sends the commands
and processes the response.
Code: |
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOPUT,NOBROWNOUT,NOLVP
#device *=16 CCSICD=TRUE
#use delay(clock = 20000000)
#use rs232(STREAM=GPS,baud=9600, xmit=PIN_c6, rcv=PIN_c7, parity=N, bits=8)
#use rs232(DEBUGGER)
#define get_nmea_mode "Ci"
#define get_time "Aa"
#define get_gmt "Ab"
#define get_date "Ac"
#define get_lat "Ad"
#define get_long "Ae"
#define get_ascii_pos "Eq"
#define get_nmea_pos "Ea"
char buff[256]; ///// assumes int8 roll over at 255
int8 next_ptr; //// next available byte in the circular buffer
int8 read_ptr;
int8 free_space;
int8 sentence_count;
struct time_struc
{
int8 hrs;
int8 mins;
int8 secs;
};
union
{
struct time_struc time;
int8 buff[3];
}time_rec;
struct date_struc
{
int8 day;
int8 month;
int8 yh;
int8 yl;
int16 year;
};
union{
struct date_struc date;
int8 buff[4];
}date_rec;
struct GMT_struc{
int8 sign;
int8 hr;
int8 min;
};
union{
struct GMT_struc GMT;
int8 buff[3];
}gmt_rec;
struct pos_struc
{
int8 month;
int8 day;
int8 yh;
int8 yl;
int8 hrs;
int8 mins;
int8 secs;
int32 fract;
};
#byte RCREG=0x0FAE
#int_rda
void gps_isr()
{
char c;
/// note this routine needs to as short as possible since it is called
/// for each char received from GPS
/// the routine places NMEA sentences into the buffer and inc sentence count
/// a sentence begins with $GP and ends /n/r
c=RCREG ; // get data from RCREG hardware clears RCIF
buff[next_ptr++]=c;// rolls over at 255 circular buffer
free_space--;
if(free_space==0)
{
puts("full buffer");
}
}
int8 buff_getc()
{
int8 c;
while( free_space==255); /// wait for data in buffer
c=buff[read_ptr++];// circular buffer rolls over at 255
free_space++;
if ( free_space==0)
{
puts("exceeded buffsize");
}
return(c);
}
void send_cmd(char *cmd, char *c,int8 length)
{
int8 i,chk_sum;
///// compute the check sum
chk_sum=cmd[0]^cmd[1];;
for(i=0;i<length;i++){
chk_sum^=c[i];
//putc(c[i]);
}
fputc('@',GPS);
fputc('@',GPS);
fputc(cmd[0],GPS);
fputc(cmd[1],GPS);
for(i=0;i<length;i++) fputc(c[i],GPS); /// payload
fputc(chk_sum,GPS);
fputc(13,GPS);
fputc(10,GPs);
}
int8 get_response (char *cmd,int8 *res_buff,int8 len)
{
int8 i,match,c;
//// a response repeats the cmd Ex @@Aa and ends with CR LF
////
match=0;
while ( match<4)
{
if (free_space!=sizeof(buff))
{
// we have data so we adv until we have @@xx xx=cmd Ex Aa
c=buff_getc();
if (c==cmd[1] && match==3)match=4;
if (c==cmd[0] && match==2) match=3;
if (c=='@' && match==1) match=2;
if (c=='@' && match==0) match=1;
}
}
match=0;
i=0; //// 0,1,2,3 chars read so far
while ( i<len-4)
{
if (free_space!=sizeof(buff))
{
// we have data
c=buff_getc();
res_buff[i++]=c;
}
}
return (i);
}
int8 get_nmea (char *cmd,int8 *res_buff)
{
int8 i,match,c;
//// a response repeats the cmd Ex GLL is $GPSGLL and ends with *CC CR LF
////
match=0;
while ( match<7>=32 && c<127) res_buff[i++]=c;
}while (c!='*');
res_buff[i]=0;
match=0;
while ( match<2)
{
c=buff_getc();
if (c=='\n' && match==1) match=2;
if (c=='\r' && match==0) match=1;
}
return (i);
}
void main()
{
int16 i;
char msg[16]; //// command msg buffer
char cmd[4];
char c;
int8 line[100];
read_ptr=0;
next_ptr=0;
free_space=255;
printf("start \n\r");
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
for(i=1;i<3;i++)
{
///////// assume 9600 baud rate at start up
/// preemptively switch to NMEA mode
set_uart_speed(9600,GPS);
sprintf(cmd,get_nmea_mode);
msg[0]=0x01;
send_cmd(cmd,msg,1);
delay_ms(1000);
}
//// should now be in 4800 baud Nmea mode
set_uart_speed(4800,GPS);
/////////////// get nmea mode ///////////////////////
/////////////////////////////////////////////////
putc(10);
putc(13);
putc(10);
putc(13);
puts("NMEA");
putc(10);
putc(13);
repeat:
putc(10);
putc(13);
puts("GLL");
putc(10);
putc(13);
fputs("$PMOTG,GLL,0000\r\n",GPS);
sprintf(cmd,"GLL");
get_nmea(cmd,line);
puts(line);
putc(10);
putc(13);
puts("RMC");
putc(10);
putc(13);
fputs("$PMOTG,RMC,0000\r\n",GPS);
sprintf(cmd,"RMC");
get_nmea(cmd,line);
puts(line);
putc(10);
putc(13);
puts("VTG");
putc(10);
putc(13);
fputs("$PMOTG,VTG,0000\r\n",GPS);
sprintf(cmd,"VTG");
get_nmea(cmd,line);
puts(line);
putc(10);
putc(13);
puts("ZDA");
putc(10);
putc(13);
fputs("$PMOTG,ZDA,0000\r\n",GPS);
sprintf(cmd,"ZDA");
get_nmea(cmd,line);
puts(line);
goto repeat;;
while(1);
}
|
|
|
|
|
|
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
|