Serial Bit Error when using SD write


I’ve the following Hardware Setup:
Adafruit Ultimate GPS (Adafruit Ultimate GPS Breakout - 66 channel w/10 Hz updates [Version 3] : ID 746 : $39.95 : Adafruit Industries, Unique & fun DIY electronics and kits) connected to Serial2 (PIN 16, PIN 17)
SD-Modul connected to I2C (MOSI 23; MISO 19; SCK 18, CS 5)
Serial0 connected to Laptop
There is also a ICM20948 Gyro in Code wich is currently disconnected for debugging purpose.
And a Neopixel which is also disconnected for debugging

Easy description of function:
I read GPS signals from serial2, format it and write it to SD-Card and print it to Serial0

The problem:
I got Bit Errors while reading GPS Data from Serial2. Some Examples:

             ^^^^ - Error. Should be "....014411.700,A,....."

When I disable the writing to SD and just output to Serial0 I have no errors.

The amount of errors seem to depends on how often I use SD.flush(). When using SD.flush() after every written Line, I got up to 70-80% of corrupt Data.
When reduce SD.flush() to every 5sec. (Which are 50 Lines) The errors go down to appr. 10%.

The corrupt Data is not sync. to the flush command. This mean, I can not say that exactly at the time when using SD.flush() I got corrupt Data.

I’m not sure if this is a code problem or a hardware problem. Does anybody have an idea how to debug it closer or how to fix it?


main.cpp (12.5 KB)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.