Example program BackwardCompatibility.ino doesn't work with SDfat
I tried this while trying to learn how to use sdfat. I can't get beyond SD.begin(). It always returns zero when using the SDFat library. it works fine with the SD.h library.
I tested this on an Arduino Uno R4 wifi. I was using pin 10 as CS and Pins 11 (MOSI), 12 (MISO), and 13 (SCLK), the standard SPI pins.
The backward compatibility program works fine when run with sd.h but fails when using sdfat.h.
Monty Shaw [email protected]
It may be your SD socket/module or wiring. SdFat uses a much higher default SPI clock than SD.h. SD.h is based on an old version of SdFat that I wrote in 2009 and used 4 MHz as the default clock.
To get full performance from SdFat you will need a quality SD module with short clean wiring and learn to use SdSpiConfig.
See this area of the bench example.
For modern SD cards you can only get high performance with dedicated SPI. Also note that the Uno R4 has a very poor implementation of SPI.
Here is the default result of bench on an Uno R4 with an Adafruit SD shield, no better than a Uno R3:
write speed and latency speed,max,min,avg KB/Sec,usec,usec,usec 612.67,851,830,832 612.59,851,830,833
read speed and latency speed,max,min,avg KB/Sec,usec,usec,usec 591.30,865,860,863 591.30,865,860,863
Here is an old Arduino Due:
write speed and latency speed,max,min,avg KB/Sec,usec,usec,usec 4537.21,1149,110,111 4537.21,128,110,111
read speed and latency speed,max,min,avg KB/Sec,usec,usec,usec 4545.45,113,110,110 4553.73,112,110,110
Thanks for the quick reply.
I did get the example to work by adding this around line 20: #define SPI_CLOCK 25 #define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
I also added this further down in the setup function:
#if USE_SD_H
if (!SD.begin(SD_CS_PIN)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
#else
if (!SD.begin(SD_CONFIG)) {
SD.initErrorHalt(&Serial);
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
#endif
OK I probably brought the clock down by using 25.
What is a good value for SPI_CLOCK? I don't know where this is defined, as I had to add my own #define SPI_CLOCK to get it to compile.
Monty
What is a good value for SPI_CLOCK? I don't know where this is defined, as I had to add my own #define SPI_CLOCK to get it to compile.
See this.
With Uno R4 and an Adafruit SD Shield I use 50 MHz. The SPI library should choose the highest speed the board will support that is less than or equal to 50 MHz.
Thanks