Hi Sorunome (and Rodot, and Milk)
I got interested in your problem (saving the EEPROM) so I took a short look. I might be wrong but two things come to my attention.
In your loader.ino main program:
- Code: Select all
SPI.setClockDivider(SPI_CLOCK_DIV128); //lower the SPI speed for better compatibility
initres=file.initFAT();
Are you aware that unless a speed is specified in file.initFAT(...here is supposed to be the speed parameter ...); the TinyFAT library defaults to maximum SPI speed ? In TinyFAT.h there is:
- Code: Select all
initFAT(byte speed=SPISPEED_HIGH);
... which means that if initFAT is called
without a parameter, speed is given the value SPISPEED_HIGH.
This means that there is a possibility of a conflict between you setting the SPI_CLOCK_DIV128 and what the initFAT function does next. We have already found out, that the Gamebuino SD's do not like fast SPI speeds and can crap out at high speeds.
Second point, BINARY DATA vs TEXT FILE
TinyFAT only has a writeLn function that is intended for TEXT FILES ONLY. Now, I have not checked what the EEPROM data actually is, but for example if the EEPROM data is a 0x00, what it actually means to the writeLn function (which takes a char* pointer as a parameter) is THE END OF STRING. Therefore, string length will be 0 and 0 bytes will be written. In order to write binary data using tinyFAT you would first have to change all your data into printable characters, so only values between 0x20 and 0x7E are allowed. Therefore, for example, the binary value 5 can not be written by writeLn(5) it has to be writeLn(5+0x30); ... ie. "5".
However, the fact that you get crap out even when you do file.writeLn("asdasfd") is saying to me that for some reason the structure "file" is somehow malformed and it is not pointing to the correct offset in the mmc structure, but is pointing into the FAT table instead. Therefore, the writeLn function writes to the wrong address in the MMC (not in the data sectors but in the FAT table).
People are using the SdFat library to write binary data to SD cards. To my knowledge, writing binary data files with TinyFAT is not supported, and Henning Karlsen has said is not going to support it. In fact, if you open a file in FILE_BINARY mode, writeLn will return with a wrong file type error.
This makes me wonder that perhaps the saveEEPROM function has NEVER worked correctly on the Gamebuino ... but I might be wrong because I do not have a Gamebuino and I have never used that function myself.