Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 5 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:
2 Answers
11 years, 5 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 12 Feb 2013I 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; } } }
11 years, 5 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.
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 2013If you copy and paste the code and surround it with
posted by Stephen Paulger 12 Feb 2013<<code>>
tags it will be easier to read and people can copy-paste it to give suggestions.