SD Card Fails to Open File After Two Writes

I need suggestions on where to look next to debug the issue I am having. Using Arduino Mega with Adafruit Ultimate GPS Logging Shield. In my project, I periodically open a file, write some text, and close the file; however, the card consistently fails to re-open the file after the second write…that is the SD initializes fine, I open the file write to it, close it, open/write/close a second time, but then all attempts from then on the card will not open again.

What I have tried so far:

  1. I have a very simple test sketch that repeatedly opens, writes to and closes a test file; that works fine, so probably not a hardware or wiring issue or issue with the SD card itself.

  2. I have tons of free memory (4K), so memory or memory not a memory leak.

  3. I have tried using a static filename and static text, so not related to the name of the file or what I am actually writing to the file.

  4. I have tried turning off the GPS interrupt before open the SD file and turning back on after the write is complete.

The key code is here, and the full sketch is attached:

File positionLog;	
positionLog = SD.open(positionFileName, FILE_WRITE);
        if (positionLog) 							// was open was successful?
      		{
      			positionLog.println(myString);		// write it to the file
      			positionLog.close();
      			Serial.println(myString);
      		}
	     else
      		{
      				Serial.println(F("SD CARD ERROR"));
          }

Any suggestions on where to look next??

RC_Car_Test_2014_07_20_002.ino.txt (27.1 KB)

Run out of RAM ?

No, tons of RAM, I'm monitoring that...what else?

dont close.. flush ? ................... Run a stripped down test to verify that the SD-routines is not working as expected.

Then check: http://forum.arduino.cc/index.php?topic=228201.0