|
|
View previous topic :: View next topic |
Author |
Message |
CCGDN
Joined: 18 May 2010 Posts: 2
|
Help for Oncore Nmea GPS with 18F4682 |
Posted: Tue May 18, 2010 4:51 am |
|
|
Hello everybody,
I'm implementing the Sw for reading information from Motorola Oncore GPS.
The code first commands the GPS switching to NMEA standard and after asking it for time information. The cmd signals seem reach the GPS (I've checked pin 9 TTL RXD with oscilloscope). Unfortunately the GPS does not react at all and none byte is received (Lcd always displays 5555).
Here in following is the code:
Code: |
#use rs232(STREAM=GPS,baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
char buff[256]; // roll over at 255
unsigned short next_ptr = 0; // next byte in the circular buffer
unsigned short read_ptr = 0; // current byte to be read
char ch;
#INT_RDA
void RDA_isr()
{
ch = fgetc(GPS);
buff[next_ptr++]=ch;// rolls over at 255 circular buffer
}
unsigned short buff_gets(char str[])
{
unsigned short i=0;
while(next_ptr != read_ptr) // read pointer different by write pointer
{
str[i] = buff[read_ptr];
i++;
read_ptr++;
};
str[i] ='\0';
return(i);
}
void main()
{
char strCmd[]="$PMOTG,RMC,0001";
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
delay_ms(1000);
set_uart_speed(9600,GPS);
for (i=0;i<2;i++) // send 2 times 0x40 0x40 0x43 0x69 0x31 0x1B 0x0D,0x0A
{
delay_ms(1000);
fputc('@',GPS);
fputc('@',GPS);
fputc('C',GPS);
fputc('i',GPS);
fputc(31,GPS);
fputc(27,GPS); //0x1b checksum
fputc(13,GPS);
fputc(10,GPS);
delay_ms(1000);
set_uart_speed(4800,GPS);
delay_ms(5000);
fputs(strCmd,GPS);
while(1)
{
len = buff_gets(msg);
memcpy(line, '\0', 256);
sprintf(line, "\f %s nc= %i\n", msg, len);
if (strlen(msg) > 0)
lcd_putc("\f4444\n");
else
lcd_putc("\f5555\n");
delay_ms(500);
for (i = 0; i < len; i++ )
lcd_putc(line[i]);
delay_ms(400);
}
}
|
I spent 2 days on this problem analyzing and changing any code raw, but without results. Could someone help me?
Thanks in advance,
CCGDN. |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Wed May 19, 2010 2:34 pm |
|
|
This code worked for me ....it might work for you
Oncore is polled it doesn't squawk like most GPS units
Code: | 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);
}
|
|
|
|
CCGDN
Joined: 18 May 2010 Posts: 2
|
|
Posted: Thu May 20, 2010 5:04 am |
|
|
Hello Douglas Kennedy,
Thanks for suggestion. I'll try with your code. However, which are get_nmea and send_cmd procedure? |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Thu May 20, 2010 5:26 am |
|
|
I did this a few years back but it might help you get an idea of what could be the issue you are having trouble with
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 in8 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)
{
c=buff_getc();
if (c==',' && match==6) match=7;
if (c==cmd[2] && match==5) match=6;
if (c==cmd[1] && match==4) match=5;
if (c==cmd[0] && match==3) match=4;
if (c=='P' && match==2) match=3;
if (c=='G' && match==1) match=2;
if (c=='$' && match==0) match=1;
}
match=0;
i=0;
do {
// we have data
c=buff_getc();
if (c>=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
|