This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

  • Resolved

MSP430FR6989: Splitting a string of data in Energia.

Intellectual 770 points

Replies: 11

Views: 807

Part Number: MSP430FR6989

Hello there,

I connected a gps module and it gives me the gps data but im unable to segregate the following data on energia

+QGNSSRD: $GNRMC,044927.000,A,1301.7816,N,07731.3016,E,0.00,93.73,290319,,,A*4F

so i need to separate the latitude and longitude, time and date.

So can anybody help me in understanding how to get the required data from the above.

i attached my code below as you can see im getting stuck in the serial read please help me in correcting this.

char gps;
int times = 1;
int count = 0;
void setup()
{ 
Serial.begin(115200);
delay(2000);
Serial.println("AT");
delay(1000);
//Serial.println("AT+CMGF=1");
Serial.println("AT+QGNSSC?");
delay(1000);

Serial.println("AT+QGNSSC=1");
delay(1000);

Serial.println("AT+QGNSSTS?");
delay(1000);

} 
void loop() {
  while(count < times)
  { 
Serial.write("AT+QGNSSRD=\"NMEA/RMC\"");
delay(2000);
if(Serial.available() >0)
{
gps=Serial.read();
 String response = "";
response +=gps;
Serial.println(response);
return response;
}
count++;
}
}

  • Hi venkatesh,

    String function in <string.h> can help you.
  • In reply to Stanford Li:

    thank you for your reply, but can you give me an example please. Still a newbie

  • In reply to r venkatesh:

    Hi,

    you may would like to take a look at this example

    and then look for further info here:


    i think this should provide the functions you are looking for.

    Regards,

     Stefan


    Please verify the answer by clicking the green  "RESOLVED MY ISSUE " button in case the reply solved your question.

  • In reply to Stefan Schauer:

    thank you for your reply .

    so this is what i came up after the above reference and other websites.

    i first tried the code using arduino the software serial works fine but in using energia i get an error for software serial as shown below.

    And secondly the data gets over written as seen below i dunno where its glitching.

    and i used "," for seperator so for the this data

    $GNRMC,070236.000,A,1301.7816,N,07731.3057,E,0.00,306.11,300319,,,D*70

    the string numbers starts like 0 for $GNRMC and 1 for 070236.000 which is the time and 2 for A which indicated valid and invalid and so on.

    so the time, latitude and status is fine but i dont see longitude even the number is correct need help with that.

    the code and screen shots are attached below.

    #include <SoftwareSerial.h> 
    SoftwareSerial mySerial(3,2);
    
    String data[7];
    #define DEBUG true
    String state,timegps,latitude,longitude;
    void setup() {
    mySerial.begin(112500);
    Serial.begin(9600);
    delay(50); 
    mySerial.println("AT");
    delay(1000);
    mySerial.println("AT+QGNSSC?");
    delay(1000);
    
    mySerial.println("AT+QGNSSC=1");
    delay(1000);
    
    mySerial.println("AT+QGNSSTS?");
    delay(1000);
    }
    
    void loop() {
      sendTabData("AT+QGNSSRD=\"NMEA/RMC\"",1000,DEBUG);
      if (state !=0) {
        Serial.println("State  :"+state);
        Serial.println("Time  :"+timegps);
        Serial.println("Latitude  :"+latitude);
        Serial.println("Longitude  :"+longitude);
        delay(300);
        mySerial.flush();
      
      }else {
        Serial.println("GPS initialising");
      }
    }
    
    void sendTabData(String command , const int timeout , boolean debug){
    mySerial.println(command);
      long int time = millis();
      int i = 0;
    
      while((time+timeout) > millis()){
        while(mySerial.available()){
          char c = mySerial.read();
          if (c != ',') {
             data[i] +=c;
             delay(100);
          } else {
            i++;  
          }
          if (i == 7) {
            delay(100);
            goto exitL;
          }
        }
      }exitL:
      if (debug) {
        state = data[2];
        timegps = data[1];
        latitude = data[3];
        longitude =data[5];  
      }
    }
    String sendData (String command , const int timeout ,boolean debug){
      String response = "";
     mySerial.println(command);
      long int time = millis();
      int i = 0;
    
      while ( (time+timeout ) > millis()){
        while (mySerial.available()){
          char c = mySerial.read();
          response +=c;
          
        }
      }
      if (debug) {
         Serial.print(response);
         }
         return response;     
    }

  • In reply to r venkatesh:

    Hi,

    SoftwareSerial has only be used or older device which did not had a hardware serial interface

    For the F6989 you can use the two implemented hardware interfaces which are available as

    Serial
    Serial1

    For the Software - you should remove the delays, otherwise you might get an input buffer overflow:

      while((time+timeout) > millis()){
        while(Serial.available()){
          char c = Serial.read();
          if (c != ',') {
             data[i] +=c;
             //delay(100);
          } else {
            i++;
          }
          if (i == 7) {
            //delay(100);
            goto exitL;
          }
        }
      }

    Regards,

     Stefan


    Please verify the answer by clicking the green  "RESOLVED MY ISSUE " button in case the reply solved your question.

  • In reply to Stefan Schauer:

    Thank you for your reply.

    The hardware serials worked thank you for that.

    But the data is totally messed up and like in the above reply if i add the delay nothing is displaying on the serial monitor but when removed the delay i get these values on the serial monitor.

  • In reply to r venkatesh:

    Hi,

    This looks strange.

    Can you share your updated code again?

    Regards,

     Stefan


    Please verify the answer by clicking the green  "RESOLVED MY ISSUE " button in case the reply solved your question.

  • In reply to Stefan Schauer:

    Hi,

    Here is the updated code there is not much changes just removed the delays.

    And also please see why that data is overlapped like in the above pic instead of giving new values every time it shows new and old one next to one another.

    String data[6];
    #define DEBUG true
    String state,timegps,latitude,longitude;
    void setup() {
    Serial1.begin(112500);
    Serial.begin(19200);
    delay(50); 
    Serial1.println("AT");
    delay(1000);
    Serial1.println("AT+QGNSSC?");
    delay(1000);
    
    Serial1.println("AT+QGNSSC=1");
    delay(1000);
    
    Serial1.println("AT+QGNSSTS?");
    delay(1000);
    }
    
    void loop() {
      sendTabData("AT+QGNSSRD=\"NMEA/RMC\"",1000,DEBUG);
      delay(500);
      if (state !=0) {
        Serial.println("State  :"+state);
        Serial.println("Time  :"+timegps);
        Serial.println("Latitude  :"+latitude);
        Serial.println("Longitude  :"+longitude);
        delay(2000);
        Serial1.flush();
      
      }else {
        Serial.println("GPS initialising");
      }
    }
    
    void sendTabData(String command , const int timeout , boolean debug){
    Serial1.println(command);
      long int time = millis();
      int i = 0;
    
      while((time+timeout) > millis()){
        while(Serial1.available()){
          char c = Serial1.read();
          if (c != ',') {
             data[i] +=c;
            //delay(70);
          } else {
            i++;  
          }
          if (i == 6) {
           // delay(70);
             
            goto exitL;
          }
        }
      }
      exitL:
      if (debug) {
        state = data[2];
        timegps = data[1];
        latitude = data[3];
        longitude =data[5];  
      }
    }
    String sendData (String command , const int timeout ,boolean debug){
      String response = "";
     Serial1.println(command);
      long int time = millis();
      int i = 0;
    
      while ( (time+timeout ) > millis()){
        while (Serial1.available()){
          char c = Serial1.read();
          response +=c;
          
        }
      }
      if (debug) {
         Serial.print(response);
         }
         return response;     
    }

    String data[6];#define DEBUG trueString state,timegps,latitude,longitude;void setup() {Serial1.begin(112500);Serial.begin(19200);delay(50); Serial1.println("AT");delay(1000);Serial1.println("AT+QGNSSC?");delay(1000);
    Serial1.println("AT+QGNSSC=1");delay(1000);
    Serial1.println("AT+QGNSSTS?");delay(1000);}
    void loop() {  sendTabData("AT+QGNSSRD=\"NMEA/RMC\"",1000,DEBUG);  delay(500);  if (state !=0) {    Serial.println("State  :"+state);    Serial.println("Time  :"+timegps);    Serial.println("Latitude  :"+latitude);    Serial.println("Longitude  :"+longitude);    delay(2000);    Serial1.flush();    }else {    Serial.println("GPS initialising");  }}
    void sendTabData(String command , const int timeout , boolean debug){Serial1.println(command);  long int time = millis();  int i = 0;
      while((time+timeout) > millis()){    while(Serial1.available()){      char c = Serial1.read();      if (c != ',') {         data[i] +=c;        //delay(70);      } else {        i++;        }      if (i == 6) {       // delay(70);                 goto exitL;      }    }  }  exitL:  if (debug) {    state = data[2];    timegps = data[1];    latitude = data[3];    longitude =data[5];    }}String sendData (String command , const int timeout ,boolean debug){  String response = ""; Serial1.println(command);  long int time = millis();  int i = 0;
      while ( (time+timeout ) > millis()){    while (Serial1.available()){      char c = Serial1.read();      response +=c;          }  }  if (debug) {     Serial.print(response);     }     return response;     }

  • In reply to r venkatesh:

    Hi,

    you have some issues in the data input handling.

    1st you need to clear your buffers.

    2nd you input stream should be received completely, even with flush it seems that there are some data still coming in.

    You can try below function and this get also rid of the jump to exit.

    void sendTabData(String command , const int timeout , boolean debug){
    Serial1.println(command);
      long int time = millis();
      int i = 0;
    
      for (i=0; i<6; i++) data[i] = "";
      i = 0;
      while((time+timeout) > millis()){
        while(Serial1.available()){
          char c = Serial1.read();
          if (i < 6) {
              if (c != ',') {
                 data[i] +=c;
              } else {
                i++;
              }
          }
        }
      }
      if (debug) {
        state = data[2];
        timegps = data[1];
        latitude = data[3];
        longitude =data[5];
      }
    }
    

    Regards,

     Stefan


    Please verify the answer by clicking the green  "RESOLVED MY ISSUE " button in case the reply solved your question.

  • In reply to Stefan Schauer:

    ohhh stefan thank you thank you thank so much
    ive been doing this since two days thank you so much...its working like a beauty....i actually commented that exit part but the data was continuously coming like junk...but now it works....now i get it
    thanks again .

    Can you please have a look at this tooo?
    e2e.ti.com/.../788788

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.