GPS Frame (UART)

Status
Not open for further replies.

achrafarhca

New Member
Hello all,
I want to read a GPS frame with an RS232 port. I use the calculator as a PIC 18F4550.
This frame contains : $ GPGGA, 115539.000,3134.6700, N, 07421.4652, E, 1,04,2.4,209.7, M, -37.5, M,, 0000 * 75.
I want to retrieve just the hour, laltitude and longitude. how I will cut this frame using mikroC?
I tried, but no results, here is the program:
Code:
char uart_rd[42];

void main() {
ADCON1 |= 0x0F;                    // Configure AN pins as digital
CMCON  |= 7;
  UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize

  UART1_Write_Text("Start");
  UART1_Write(10);
  UART1_Write(13);

  do {                     // Endless loop
    if (UART1_Data_Ready()) {     // If data is received,
      UART1_Read_Text(uart_rd, "OK",42);    // reads text until 'OK' is found
    UART1_Write_Text(uart_rd);
    }
  }   while (1);
}
 
There is no "OK" in the GPS data frame. You should look for the * at the end.

If that doesn't work, you need to check that data is being sent. You can check it with a terminal emulator on a computer.
 
this is definitely NOT a program meant for decoding nmea messages. you need to try harder.
 
thank you all for your responses
for now, I would just receive the frame, and cut it.
I wrote the code for cutting this frame. it works very well on Dev C + +. but in MikroC no!!
the problem that I can not solve it until now is the reception! i can not receive my frame!
this is my new ccode:
Code:
void uartt(){
    while(uart_rd[i] != '\0')
{
    if(uart_rd[i] == ',')
    {
               t++;
              aid[t]=i+1;

              for (k=0;k<i-debut;k++){
                  //printf("maTab[%d]=%c \n",debut+k,car[debut+k]);
              maTab[j]=uart_rd[debut+k];
              j++;
              }
   

          debut = i+1;
    }

    i++;
}
aid[0]=0;
h=0;
j=1;
for (i=0;i<aid[j]-aid[j-1]-1;i++){

 chaine1[i]=maTab[aid[j-1]+i-h];
  }
  chaine1[i]='\0';
    h++;
  j=2;
for (i=0;i<aid[j]-aid[j-1]-1;i++){
  chaine2[i]=maTab[aid[j-1]+i-h];
  }
   chaine2[i+1]='\0';
  h++;
  j=3;

   Mylat=atof(chaine2);
   FloatToStr(Mylat,chaine2);
    Lcd_Out(1, 1,"Longitude");
    Lcd_Out(2,1 ,chaine2);
      delay_ms(7000);
}

void  main()
{

LATB = 0xFF;
TRISB = 0xff;
ADCON1 |= 0x0F;                    // Configure AN pins as digital
CMCON  |= 7;                       // Disable comparators
 TRISA = 0x00;          // set direction to be output
TRISB=0;
PORTB=0;
// TRISC=0;
 UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize

  UART1_Write_Text("Start");
  UART1_Write(10);
  UART1_Write(13);
 //PORTC=0;
 Keypad_Init();                           // Initialize Keypad
 Lcd_Init();
                              // Initialize Lcd
 Lcd_Cmd(_LCD_CLEAR);                      // Clear display
 Lcd_Cmd(_LCD_CURSOR_OFF);                 // Cursor off

 do {                     // Endless loop
    if (UART1_Data_Ready()) {
     UART1_Read_Text(uart_rd, ',',70);
     Lcd_Cmd(_LCD_CLEAR);
uartt();
   
          }
    }while(1);
    }
 
I bet it doesn´t even compile, since for example variable debut is not defined nor initialized..
Anyway, I don´t know what changes are in microC but it should work. Maybe post what errors it says.
 
Last edited:
How about parsing the incoming string on-the-fly?

Code:
;
;  unsigned char field = 0;
;  unsigned char ndx = 0;
;  unsigned char time[11];
;  unsigned char lat[10];
;  unsigned char lon[11];
;
;  const rom char hdr[] = { "GPGGA" };
;
;  #define parser (field <= 5)	  // parser on (1) or off (0)
;
;  void main()
;  { initmcu();                   //
;    initlcd();                   //
; 
;    while(1)
;    { data = Get232();		  // get gps character
;      if(data == '$')		  // if new 'sentence'
;      { field = 0; ndx = 0;	  // reset field and index
;      }			  //
;      else			  // not new sentence, so
;      { if(parser)		  // if parser 'on'
;        { if(data == ',')	  // if new field
;          { field++; ndx = 0;	  // bump field, reset index
;          }			  //
;          else			  // not new field
;          { if(field == 0)	  // if header field
;            { if(data!=hdr[ndx]) // if not "GPGGA"
;                field = 5;	  // turn parser off
;            }			  //
;            if(field == 1)       //
;              time[ndx] = data;  //
;            if(field == 2)       //
;              lat[ndx] = data;   //
;            if(field == 4)       //
;              lon[ndx] = data;   //
;            ndx++;		  // bump field index
;          }			  //
;        }			  //
;      }			  //
;    }				  //
;  }                              //
;
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…