Closed CptHolzschnauz closed 1 year ago
what Arduino board?
mkr1010
what error do you get?
if (!SD.begin(SDCARD_SS_PIN)) {
Can't initialize (So return 0)
File file = SD.open(BIN_FILENAME, O_CREAT | O_WRITE);
Can't open/create file.
Sry, i'm in transit away from my dev desk so i can't give more precise answer at the moment.
It's not the card or it's filesystem, i checked that.
do you have the MKR 1010 selected in Tools menu? (because if you have Zero selected, then SDCARD_SS_PIN is 28 from variant.h)
in SD library
#define FILE_WRITE (O_READ | O_WRITE | O_CREAT | O_APPEND)
we don't want O_APPEND if the file already exists
Yes. Your comment makes sense, the
#define FILE_WRITE (O_READ | O_WRITE | O_CREAT | O_APPEND)
is a bit strange bacause it means everything, like a general approach but thats a SD thing.
File file = SD.open(BIN_FILENAME, O_CREAT | O_WRITE);
makes sense but this may cause issues.
In the SD lib examples they check for a existing file, if existing remove it and then make a new one. Maybe this approach is more failsafe in SD.h, i don't know. I will do some further testing when i'm back and report here. Thx & you rock!
Just a thought: Why not use sdfat.h instead of sd.h? sd.h is a old fork of sdfat.h. sdfat.h seems to be more maintained.
I like the SD library
In examples/Advanced/OTASketchDownload_SD)/OTASketchDownload_SD.ino It's:
#define SDCARD_SS_PIN 4
And thenif (!SD.begin(SDCARD_SS_PIN)) {
And thenFile file = SD.open(BIN_FILENAME, O_CREAT | O_WRITE);
Which leads in my project to a SD failure trying SD.open .
With
if (!SD.begin(4)) {
andFile file = SD.open(BIN_FILENAME, FILE_WRITE);
It worked. The SD.begin(4) is probably superstitious because the compiler should come with the same code, the FILE_WRITE is maybe wanted by a newer SD.h version. The pure example as it is works, but as i said not with a longer sketch. Don't know why.
Suggestion: Replace
File file = SD.open(BIN_FILENAME, O_CREAT | O_WRITE);
withFile file = SD.open(BIN_FILENAME, FILE_WRITE);