11 years, 2 months ago.

Serial communication problem

I am trying to read data from a GPS receiver. The program just gets stuck when it comes to reading the data. I guess the buffer gets full. Is there any way i can solve this?

<<Code>>

int main() {

GPS.baud(9600); Set the baud rate to 9600 GPS.format(8,Serial::None,1); 8 bits , no parity bits, 1 stop bit

char input[] = ""; Led1 = 1; while(1) {

if(!GPS.readable()); Led1 = 0;

GPS.scanf("%s",&input); Led1 = 1;

}

} }

1 Answer

11 years, 2 months ago.

int main() {

  GPS.baud(9600); //Set the baud rate to 9600
  GPS.format(8,Serial::None,1); // 8 bits , no parity bits, 1 stop bit

  char input[] = "";
  Led1 = 1;

  while(1) {

   if(!GPS.readable());
   Led1 = 0;

   GPS.scanf("%s",&input);
   Led1 = 1;
 }
}

Your input char array should have sufficient room to store the GPS string. You currently declare it as an array with room for 0 characters by initialising it as empty string

Try this:

  ...
  char input[128];
  ...

You should also change the if(!GPS.readable()). It wont wait until data is available, but rather just do nothing and continue.

Note that there are GPS decoder libs on the mbed website. You dont have to roll your own.