Paraglider
Well-known member
When logging data to an SD card using SD FAT and reading/parsing GPS NMEA strings using TinyGPSPlus in the same loop then the there there are checksum errors. On an average 1 of 30 or 40 GPS readings is corrupt when logging lots of data from an AHRS, baro and GPS with 50Hz. When using dummy data, so no reading of IMU and pressure sensor then the error is the same, there are roughly the same amount of checksum errors over time. But when logging data only at 5Hz for a KML file then the checksum errors rarely appear.
I already increased the RX buffer for the GPS to 250, but there was no difference to see. The GPS outputs NMEA strings with 115200 baud at 5Hz, so the buffer should be big enough. It looks like it has something to do with the writing of the data to the SD card, like the RX buffer of Serial1 would be blocked when data is written to the SD card. Data is added to a string, and whenever the string is longer than 512 then the 512 first bytes are written to the SD card.
The relevant code snippets are as follows:
Read data from GPS using serialEvent1:
Data is written to the SD card in chuncks of 512 bytes:
How can I solve this problem? Is this issue related to SPI transaction?
I already increased the RX buffer for the GPS to 250, but there was no difference to see. The GPS outputs NMEA strings with 115200 baud at 5Hz, so the buffer should be big enough. It looks like it has something to do with the writing of the data to the SD card, like the RX buffer of Serial1 would be blocked when data is written to the SD card. Data is added to a string, and whenever the string is longer than 512 then the 512 first bytes are written to the SD card.
The relevant code snippets are as follows:
Code:
#define GPSSerial Serial1
static const uint32_t GPSBaud = 115200;
Read data from GPS using serialEvent1:
Code:
void serialEvent1() {
while (GPSSerial.available()) {
char c = GPSSerial.read();
gps.encode(c);
}
}
Data is written to the SD card in chuncks of 512 bytes:
Code:
file.print(SDbufStr);
file.sync();
How can I solve this problem? Is this issue related to SPI transaction?