while(!Serial.available()); //wait buffer to get some data
before this:
com = Serial.read();
It is pointless to read from the serial buffer without knowing whether there was anything to read. It is pointless to use the value returned by read() without determining if the value meant "Oops, there was nothing to read...".
PaulS:
It is pointless to read from the serial buffer without knowing whether there was anything to read. It is pointless to use the value returned by read() without determining if the value meant "Oops, there was nothing to read...".
I don't think this is the case.
Maybe with an unorthodox way but I do wait for a flag to be raised before I try to read data.
void setup(){
...
while(!Serial.available()); //Not leaving unless I'm ready for reading
}
void loop(){
com = Serial.read(); //Read only one byte
...
while(!Serial.available()); //Don't loop unless next byte is there waiting
}
PS It may looks dumb using two times the same while() but
I need to stay in setup() routine until GPS is connected
For anyone that may concern: problem temporary fixed by using a 400-byte char array
Using this code with Serial.print() everything were fine.
After commenting and switching to file.print() I get relative many faulty/chopped NMEA sentences
void loop(){
char com = 0;
while(!Serial.available()) delayMicrosedeonds(32);
com = Serial.read();
//Serial.print(com);
file.print(com);
}
Now I’m using this code and everything are fine once again