SDFat example BackwardCompatibility.ino Broke

I am trying to use the sdfat library because it supports the kind of things that you need to do with a SD like RENAME a file. I started with the BackwardCompatibility.ino example from the sdfat library. This example opens a file on the sd card writes to it and then reads the lines written back out. However this example runs fine when you #define USE_SD_H 1 which makes it use SD.h, but if you make it use the sdfat library by #define USE_SD_H 0 then the SD won't even initialize. (SD.begin returns zero)

This appears to fail with the latest sdfat library (2.3.0) or the previous one (2.2.3)

Did anyone else notice this? Or does sdfat not initialize with SD.begin?

how do I let the author of sdfat know?

Monty

Which board are you compiling for? The example that you mention has no problem initialising the SD card with #define USE_SD_H 0 and connected to a SparkFun Pro Micro. I'm using a 16GB card.

I see that you already figured that out. I suggest that you add some details to your issue report (Example program BackwardCompatibility.ino doesn't work with SDfat · Issue #520 · greiman/SdFat · GitHub).

Arduino Uno R4 WiFi is the board. I should have mentioned that. I did get it to work finally but I had to change the example program by changing a couple of parts of the example program. I have them marked.

// A simple read/write example for SD.h.
// Mostly from the SD.h ReadWrite example.
//
// Your SD must be formatted FAT16/FAT32.
//
// SD.h does not support some default SdFat features.
// To compare flash size, set USE_FAT_FILE_FLAG_CONTIGUOUS,
// ENABLE_DEDICATED_SPI, and USE_LONG_FILE_NAMES to zero also
// set SDFAT_FILE_TYPE to one in SdFat/src/SdFatCongfig.h
//
// Set USE_SD_H nonzero to use SD.h.
// Set USE_SD_H zero to use SdFat.h.
//
#define USE_SD_H 0
//
#if USE_SD_H
#include <SD.h>
#else  // USE_SD_H
#include "SdFat.h"
SdFat SD;
//////////////////////////  this is the part I changed ///////////////
#define SPI_CLOCK 25
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
///////////////////////////////////////////////////////////////////////
#endif  // USE_SD_H

// Modify SD_CS_PIN for your board.
// For Teensy 3.6 and SdFat.h use BUILTIN_SDCARD.
#define SD_CS_PIN SS

File myFile;

void setup() {
  Serial.begin(9600);
  while (!Serial) {
  }

#if USE_SD_H
  Serial.println(F("Using SD.h. Set USE_SD_H zero to use SdFat.h."));
#else   // USE_SD_H
  Serial.println(F("Using SdFat.h. Set USE_SD_H nonzero to use SD.h."));
#endif  // USE_SD_H
  Serial.println(F("\nType any character to begin."));
  while (!Serial.available()) {
    yield();
  }
  Serial.print("Initializing SD card...");

//////////////////////////  this is the part I changed ///////////////
#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
//////////////////////////////////////////////////////////////////////

  // open the file.
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}
void loop() {
  // nothing happens after setup
}

That seems to fix it although I was guessing at the correct value of SPI_CLOCK

Monty

EDIT: I tried this again with 50 for the clock and it worked as well.