Hello,
Is it possible that the SD I/O libraries for the Sakura have a bug for writing right now? It seems that we only get files filled with wrong characters and even corrupt files at the moment.
The codes for writing in our specific case have not been changed, but the output is changed dramatically. (as of 9-1-2018 for as far as we know)
-美月
Hello JB, I have since uploaded the example program and that one gives problems too. It can be read by the Sakura before it is close();'d, but after that I can't read it back on PC. Is it perhaps known whether there are demands for certain cluster sizes, SD card sizes or anything? I do know about the 8.3 names requirement. As for saving within my project, does it give problems if I first manually SD.flush(); and then SD.close();, since SD.close(); flushes as well? The reference does not mention anything about it not being allowed.
Quick update: I just removed the SD.flush(); attempt to make it work and it stillproduces a file that cannot be opened on a PC. This also means that the file is not read by the Sakura.
Hello JB,
In my last message I told that I tried the demo program and that the data in it cant be read back on a PC (which is a requirement, by the way). I have since tried some more things, and at the moment I can write a file ..sometimes. When I try opening a file, it will not always do it. Generally, from the 2nd attempt on it will succesfully open a file for writing. Once, it worked the first time, but it produced a file of nearly 4GB, that was 0B when I tried to delete it.
I will post my piece of code below. Note that I changed variable names.
if (SD.exists("filename.txt") && !xOnlyDeleteOnce){ SD.remove("filename.txt"); xOnlyDeleteOnce = true; } fileVar = SD.open("filename.txt", FILE_WRITE); if (fileVar) {fileVar.print(intVar1); delay(5);fileVar.print(","); delay(5);fileVar.print(intVar2); delay(5);fileVar.print(","); delay(5);fileVar.print(intVar3); delay(5);fileVar.print(","); delay(5);fileVar.print(intVar4); delay(5);fileVar.print(","); delay(5);fileVar.print(intVar5); delay(5);fileVar.print(","); delay(5);fileVar.print(intVar6); delay(5);fileVar.print(","); delay(5);fileVar.print(floatVar1, 2); // print two decimal places delay(5);fileVar.print(","); delay(5);fileVar.print(floatVar2, 2); // print two decimal places delay(5);fileVar.println(","); // Ends line and inserts cr/lf delay(5); delay(300); //@TODO test this -> didn't workfileVar.close(); Serial.println("Done writing!"); } else { errorFlag = true; errorCode = 11; } // This is followed by if (!fileVar) { //code to return to main scenario }
if (SD.exists("filename.txt") && !xOnlyDeleteOnce){ SD.remove("filename.txt"); xOnlyDeleteOnce = true; }
fileVar = SD.open("filename.txt", FILE_WRITE);
if (fileVar) {fileVar.print(intVar1); delay(5);fileVar.print(","); delay(5);fileVar.print(intVar2); delay(5);fileVar.print(","); delay(5);fileVar.print(intVar3); delay(5);fileVar.print(","); delay(5);fileVar.print(intVar4); delay(5);fileVar.print(","); delay(5);fileVar.print(intVar5); delay(5);fileVar.print(","); delay(5);fileVar.print(intVar6); delay(5);fileVar.print(","); delay(5);fileVar.print(floatVar1, 2); // print two decimal places delay(5);fileVar.print(","); delay(5);fileVar.print(floatVar2, 2); // print two decimal places delay(5);fileVar.println(","); // Ends line and inserts cr/lf delay(5); delay(300); //@TODO test this -> didn't workfileVar.close(); Serial.println("Done writing!"); } else { errorFlag = true; errorCode = 11; }
// This is followed by
if (!fileVar) { //code to return to main scenario }
I hope that you, or anyone else, can help me fix this problem
Ok. There is no description in libraries. The version is only described template name or default sketch as below.
If you could, try the latest version V2.20 downloadable at GR-SAKURA web. http://gadget.renesas.com/en/product/sakura.html
Note that the projects can be used with e2studio V5.4, not for V6.x.
I've tried the below code on my e2studio 5.4 (GNURX 14.03).
/* GR-SAKURA Sketch Template V2.20 */#include <Arduino.h>#include <SD.h>static int intVar1, intVar2, intVar3, intVar4, intVar5, intVar6;static float floatVar1, floatVar2;static bool errorFlag = false;static bool xOnlyDeleteOnce = false;static uint8_t errorCode = 0;void setup() { Serial.begin(9600); if (!SD.begin()) { Serial.println("Card failed, or not present."); while (1) ; }}void loop() { Serial.println("Any key to start writing."); while (!Serial.available()) ; // wait to press key Serial.read(); //dummy if (SD.exists("filename.txt") && !xOnlyDeleteOnce) { SD.remove("filename.txt"); xOnlyDeleteOnce = true; } File fileVar = SD.open("filename.txt", FILE_WRITE); if (fileVar) { fileVar.print(intVar1); delay(5); fileVar.print(","); delay(5); fileVar.print(intVar2); delay(5); fileVar.print(","); delay(5); fileVar.print(intVar3); delay(5); fileVar.print(","); delay(5); fileVar.print(intVar4); delay(5); fileVar.print(","); delay(5); fileVar.print(intVar5); delay(5); fileVar.print(","); delay(5); fileVar.print(intVar6); delay(5); fileVar.print(","); delay(5); fileVar.print(floatVar1, 2); // print two decimal places delay(5); fileVar.print(","); delay(5); fileVar.print(floatVar2, 2); // print two decimal places delay(5); fileVar.println(","); // Ends line and inserts cr/lf delay(5); delay(300); //@TODO test this -> didn't work fileVar.close(); Serial.println("Done writing!"); } else { errorFlag = true; errorCode = 11; }}
The below image show that "FILENAME.TXT" was written, and show the contents in the file. It works fine.
Next, I modified the program as below, "delay" was removed.
/* GR-SAKURA Sketch Template V2.20 */#include <Arduino.h>#include <SD.h>static int intVar1, intVar2, intVar3, intVar4, intVar5, intVar6;static float floatVar1, floatVar2;static bool errorFlag = false;static bool xOnlyDeleteOnce = false;static uint8_t errorCode = 0;void setup() { Serial.begin(9600); if (!SD.begin()) { Serial.println("Card failed, or not present."); while (1) ; }}void loop() { Serial.println("Any key to start writing."); while (!Serial.available()) ; // wait to press key Serial.read(); //dummy if (SD.exists("NODELAY.txt") && !xOnlyDeleteOnce) { SD.remove("NODELAY.txt"); xOnlyDeleteOnce = true; } File fileVar = SD.open("NODELAY.txt", FILE_WRITE); if (fileVar) { fileVar.print(intVar1); fileVar.print(","); fileVar.print(intVar2); fileVar.print(","); fileVar.print(intVar3); fileVar.print(","); fileVar.print(intVar4); fileVar.print(","); fileVar.print(intVar5); fileVar.print(","); fileVar.print(intVar6); fileVar.print(","); fileVar.print(floatVar1, 2); // print two decimal places fileVar.print(","); fileVar.print(floatVar2, 2); // print two decimal places fileVar.println(","); // Ends line and inserts cr/lf fileVar.close(); Serial.println("Done writing!"); } else { errorFlag = true; errorCode = 11; }}
The below image shows that "NODELAY.TXT" was written, and show the contents in the file. It works fine.
Could you tell me the version of compiler ? I used GNURX v14.03, that is little bit old.
Anyway, __RX600__ is activated by -mcpu=rx600. We had integrated the library for GR-SAKURA and GR-CITRUS(RX631) so we use __RX600__ macro.