11 years, 2 months ago.

Cannot read data from the serial port.I mean the program just freezes as it comes to reading data

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

Led1 = 1; while(1) {

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

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

Led1 = 1;

}

} }

Question relating to:

I am just trying to see where the program is stopping by using flags. I have found out that it stops at the communication bit. I guess it cannot communicate with the GPS and stops there trying to do it.

posted by Ashwin Vanpal 12 Feb 2013

If you copy and paste the code and surround it with <<code>> tags it will be easier to read and people can copy-paste it to give suggestions.

posted by Stephen Paulger 12 Feb 2013

2 Answers

11 years, 2 months ago.

You check if you cannot read from the serial port, and if you cannot do it, you read from the serial port, but you just made sure you cannot read from it.

That said it should then only block until your gps sends data, so I would make sure if it actually sends you data.

The GPS readable function works and sends 1 which means that the Data is available for reading. When I try to read it the code gets stuck.

posted by Ashwin Vanpal 12 Feb 2013

I misread your code, your if block doesnt do anything whatsoever, which is a bit confusing. You check if the gps serial is NOT readable, but then it doesnt do anything with it. Isnt that supposed to be a while not readable?

I would make a serial bridge and check what it receives? (Random copy paste of serial bridge)

#include "mbed.h"
 
Serial pc(USBTX, USBRX); // tx, rx
Serial device(p9, p10);  // tx, rx
DigitalOut rxLed(LED1);
DigitalOut txLed(LED2);
 
int main() {
    while(1) {
        if(pc.readable()) {
            device.putc(pc.getc());
            txLed =! txLed;
        }
        if(device.readable()) {
            pc.putc(device.getc());
            rxLed =! rxLed;
        }
    }
}
posted by Erik - 12 Feb 2013

I checked the GPS data on the scope and found that it is sending the data. About the GPS.readable it should have been in while.

Thanks for the help. I am still struggling with it so let me know if you have any more suggestions.

posted by Ashwin Vanpal 16 Feb 2013
11 years, 2 months ago.

See my answer on this question in your other thread: Your char input array has size 0. That means it can not store the gps data.