SDfat problem on UNO with Shield but not on Wemos D1 with Shields

I have a problem I do not understand with the Sdfat lib.

I get my Wemos D1 mini working with the Lolin MicroSD card shield and the Robotdyn MicroSD card shield. It is working without modifications.

But I do not get my UNO working with the RobotDyn MicroSD card shield for UNO. When running Quikstart.ino it is working (it also works with the small SD.h lib)

Shield: https://robotdyn.com/data-logger-shield-for-arduino-microsd-card-rtc.html

Quickstart says:
MISO: 12
MOSI: 11
SCK: 13
SS: 10
But when using SS = 9 it works (with quickstart.ino and the small SD.h). But I can not get another file working from the SDfat lib examples.

When I use the other sketches from the example folder it won't work. When using the original SdInfo.ino I get error:

21:05:41.046 -> error: cardSize failed
21:05:41.046 -> SD errorCode: 0X50,0X20

When I change
const uint8_t SD_CHIP_SELECT = 9;
I still get the same error. Or when using SS.
What problem do I not see?

Why do I not get the Uno working with the RobotDyn SDcard shield
Do I have to change the MOSI MISO and CLK pins somewhere when I change my board from esp8266 to Uno? Because they are also different on Uno vs ESP8266.

not sure about all of it but regarding this

Why do I not get the Uno working with the RobotDyn SDcard shield
Do I have to change the MOSI MISO and CLK pins somewhere when I change my board from esp8266 to Uno? Because they are also different on Uno vs ESP8266.

you dont have to assign the miso mosi and clk but you do have to use the inputs designated for those on the hardware you are using.

you will need to tell it what the CS pin it though

I ran into the same issue between a mega 2560 and a uno max. just had to move my wires to the correct pins on the 2560 controller and everything started working correctly.

you should be defining these before the setup normally.

something like this
const int SD_CS = 53; //CS pin for SD card reader

or just int SD_CS = 53;

i hear they both work

then you need this as well normally

pinMode(SD_CS, OUTPUT); //sets the SD cards CS pin to output

then when you do your if statement it normally looks like this

if (!SD.begin(SD_CS))

but then you also seem to be using the old SDfat instead of the new SD library Id have to see your code to say for sure

your likely to get more help if you post your sketch so the smart ones can pick it apart. and tell you exactly where your going wrong if it is in fact a code issue and not a hardware issue.

jmppts:
you will need to tell it what the CS pin it though

something like this
const int SD_CS = 53; //CS pin for SD card reader

or just int SD_CS = 53;

I do tell what the CS pin is. In my first post I showed that I change the
const uint8_t SD_CHIP_SELECT = 9;

Because the Robotdyn Shield has de CS on 9. I get it working with the SD.lib. But I do not get it working with the SDfat.lib

jmppts:
but then you also seem to be using the old SDfat instead of the new SD library Id have to see your code to say for sure

your likely to get more help if you post your sketch so the smart ones can pick it apart. and tell you exactly where your going wrong if it is in fact a code issue and not a hardware issue.

The Old SDfat.lib? I downloaded it last week from GitHub. Is this the correct one: GitHub - greiman/SdFat: Arduino FAT16/FAT32 exFAT Library ?

I can post the codes I use. But I use the original examples from SDfat and change the CS pin.
I get the old SD.lib originally on my Arduino IDE to work with all my boards and shields but the SDfat.lib I only get to work with my ESP8266 boards with different shields. But I do not get it to work with an Uno and a Robotdyn Shield.

The SdInfo code from examples I use:

/*
 * This program attempts to initialize an SD card and analyze its structure.
 */
#include <SPI.h>
#include "SdFat.h"
#include "sdios.h"

// Set USE_SDIO to zero for SPI card access. 
#define USE_SDIO 0
/*
 * SD chip select pin.  Common values are:
 *
 * Arduino Ethernet shield, pin 4.
 * SparkFun SD shield, pin 8.
 * Adafruit SD shields and modules, pin 10.
 * Default SD chip select is the SPI SS pin.
 */
const uint8_t SD_CHIP_SELECT = 9;
/*
 * Set DISABLE_CHIP_SELECT to disable a second SPI device.
 * For example, with the Ethernet shield, set DISABLE_CHIP_SELECT
 * to 10 to disable the Ethernet controller.
 */
const int8_t DISABLE_CHIP_SELECT = 9;

#if USE_SDIO
// Use faster SdioCardEX
SdFatSdioEX sd;
// SdFatSdio sd;
#else // USE_SDIO
SdFat sd;
#endif  // USE_SDIO

// serial output steam
ArduinoOutStream cout(Serial);

// global for card size
uint32_t cardSize;

// global for card erase size
uint32_t eraseSize;
//------------------------------------------------------------------------------
// store error strings in flash
#define sdErrorMsg(msg) sd.errorPrint(F(msg));
//------------------------------------------------------------------------------
uint8_t cidDmp() {
  cid_t cid;
  if (!sd.card()->readCID(&cid)) {
    sdErrorMsg("readCID failed");
    return false;
  }
  cout << F("\nManufacturer ID: ");
  cout << hex << int(cid.mid) << dec << endl;
  cout << F("OEM ID: ") << cid.oid[0] << cid.oid[1] << endl;
  cout << F("Product: ");
  for (uint8_t i = 0; i < 5; i++) {
    cout << cid.pnm[i];
  }
  cout << F("\nVersion: ");
  cout << int(cid.prv_n) << '.' << int(cid.prv_m) << endl;
  cout << F("Serial number: ") << hex << cid.psn << dec << endl;
  cout << F("Manufacturing date: ");
  cout << int(cid.mdt_month) << '/';
  cout << (2000 + cid.mdt_year_low + 10 * cid.mdt_year_high) << endl;
  cout << endl;
  return true;
}
//------------------------------------------------------------------------------
uint8_t csdDmp() {
  csd_t csd;
  uint8_t eraseSingleBlock;
  if (!sd.card()->readCSD(&csd)) {
    sdErrorMsg("readCSD failed");
    return false;
  }
  if (csd.v1.csd_ver == 0) {
    eraseSingleBlock = csd.v1.erase_blk_en;
    eraseSize = (csd.v1.sector_size_high << 1) | csd.v1.sector_size_low;
  } else if (csd.v2.csd_ver == 1) {
    eraseSingleBlock = csd.v2.erase_blk_en;
    eraseSize = (csd.v2.sector_size_high << 1) | csd.v2.sector_size_low;
  } else {
    cout << F("csd version error\n");
    return false;
  }
  eraseSize++;
  cout << F("cardSize: ") << 0.000512*cardSize;
  cout << F(" MB (MB = 1,000,000 bytes)\n");

  cout << F("flashEraseSize: ") << int(eraseSize) << F(" blocks\n");
  cout << F("eraseSingleBlock: ");
  if (eraseSingleBlock) {
    cout << F("true\n");
  } else {
    cout << F("false\n");
  }
  return true;
}
//------------------------------------------------------------------------------
// print partition table
uint8_t partDmp() {
  mbr_t mbr;
  if (!sd.card()->readBlock(0, (uint8_t*)&mbr)) {
    sdErrorMsg("read MBR failed");
    return false;
  }
  for (uint8_t ip = 1; ip < 5; ip++) {
    part_t *pt = &mbr.part[ip - 1];
    if ((pt->boot & 0X7F) != 0 || pt->firstSector > cardSize) {
      cout << F("\nNo MBR. Assuming Super Floppy format.\n");
      return true;
    }
  }
  cout << F("\nSD Partition Table\n");
  cout << F("part,boot,type,start,length\n");
  for (uint8_t ip = 1; ip < 5; ip++) {
    part_t *pt = &mbr.part[ip - 1];
    cout << int(ip) << ',' << hex << int(pt->boot) << ',' << int(pt->type);
    cout << dec << ',' << pt->firstSector <<',' << pt->totalSectors << endl;
  }
  return true;
}
//------------------------------------------------------------------------------
void volDmp() {
  cout << F("\nVolume is FAT") << int(sd.vol()->fatType()) << endl;
  cout << F("blocksPerCluster: ") << int(sd.vol()->blocksPerCluster()) << endl;
  cout << F("clusterCount: ") << sd.vol()->clusterCount() << endl;
  cout << F("freeClusters: ");
  uint32_t volFree = sd.vol()->freeClusterCount();
  cout <<  volFree << endl;
  float fs = 0.000512*volFree*sd.vol()->blocksPerCluster();
  cout << F("freeSpace: ") << fs << F(" MB (MB = 1,000,000 bytes)\n");
  cout << F("fatStartBlock: ") << sd.vol()->fatStartBlock() << endl;
  cout << F("fatCount: ") << int(sd.vol()->fatCount()) << endl;
  cout << F("blocksPerFat: ") << sd.vol()->blocksPerFat() << endl;
  cout << F("rootDirStart: ") << sd.vol()->rootDirStart() << endl;
  cout << F("dataStartBlock: ") << sd.vol()->dataStartBlock() << endl;
  if (sd.vol()->dataStartBlock() % eraseSize) {
    cout << F("Data area is not aligned on flash erase boundaries!\n");
    cout << F("Download and use formatter from www.sdcard.org!\n");
  }
}
//------------------------------------------------------------------------------
void setup() {
  Serial.begin(9600);
  
  // Wait for USB Serial 
  while (!Serial) {
    SysCall::yield();
  }

  // use uppercase in hex and use 0X base prefix
  cout << uppercase << showbase << endl;

  // F stores strings in flash to save RAM
  cout << F("SdFat version: ") << SD_FAT_VERSION << endl;
#if !USE_SDIO  
  if (DISABLE_CHIP_SELECT < 0) {
    cout << F(
           "\nAssuming the SD is the only SPI device.\n"
           "Edit DISABLE_CHIP_SELECT to disable another device.\n");
  } else {
    cout << F("\nDisabling SPI device on pin ");
    cout << int(DISABLE_CHIP_SELECT) << endl;
    pinMode(DISABLE_CHIP_SELECT, OUTPUT);
    digitalWrite(DISABLE_CHIP_SELECT, HIGH);
  }
  cout << F("\nAssuming the SD chip select pin is: ") <<int(SD_CHIP_SELECT);
  cout << F("\nEdit SD_CHIP_SELECT to change the SD chip select pin.\n");
#endif  // !USE_SDIO  
}
//------------------------------------------------------------------------------
void loop() {
  // Read any existing Serial data.
  do {
    delay(10);
  } while (Serial.available() && Serial.read() >= 0);

  // F stores strings in flash to save RAM
  cout << F("\ntype any character to start\n");
  while (!Serial.available()) {
    SysCall::yield();
  }

  uint32_t t = millis();
#if USE_SDIO
  if (!sd.cardBegin()) {
    sdErrorMsg("\ncardBegin failed");
    return;
  }
#else  // USE_SDIO
  // Initialize at the highest speed supported by the board that is
  // not over 50 MHz. Try a lower speed if SPI errors occur.
  if (!sd.cardBegin(SD_CHIP_SELECT, SD_SCK_MHZ(50))) {
    sdErrorMsg("cardBegin failed");
    return;
  }
 #endif  // USE_SDIO 
  t = millis() - t;

  cardSize = sd.card()->cardSize();
  if (cardSize == 0) {
    sdErrorMsg("cardSize failed");
    return;
  }
  cout << F("\ninit time: ") << t << " ms" << endl;
  cout << F("\nCard type: ");
  switch (sd.card()->type()) {
  case SD_CARD_TYPE_SD1:
    cout << F("SD1\n");
    break;

  case SD_CARD_TYPE_SD2:
    cout << F("SD2\n");
    break;

  case SD_CARD_TYPE_SDHC:
    if (cardSize < 70000000) {
      cout << F("SDHC\n");
    } else {
      cout << F("SDXC\n");
    }
    break;

  default:
    cout << F("Unknown\n");
  }
  if (!cidDmp()) {
    return;
  }
  if (!csdDmp()) {
    return;
  }
  uint32_t ocr;
  if (!sd.card()->readOCR(&ocr)) {
    sdErrorMsg("\nreadOCR failed");
    return;
  }
  cout << F("OCR: ") << hex << ocr << dec << endl;
  if (!partDmp()) {
    return;
  }
  if (!sd.fsBegin()) {
    sdErrorMsg("\nFile System initialization failed.\n");
    return;
  }
  volDmp();
}

The Old SDfat.lib? I downloaded it last week from GitHub. Is this the correct one: GitHub - greiman/SdFat: Arduino FAT16/FAT32 exFAT Library ?

although i do believe that is the latest version of the SDFat library i recommend you use the SD library it works much better. (it includes the SDFAT library contents it needs)

I do tell what the CS pin is. In my first post I showed that I change the
const uint8_t SD_CHIP_SELECT = 9;

Because the Robotdyn Shield has de CS on 9

Although your SD card Shield may be pinned out to use pin 9 for CS the controller you are using may want to use a different pin. as I said I tired forcing my mega 2560 to use pin 10 for CS and it just would not take it. I had to use pin 53 for CS and run a jumper. for this reason alone i stopped using a stack shield and got a small SD card breakout that i just pinned how I wanted it.

the problem you will run into is, you cant just plug the shield into the top of the controller if you don't use the matching pin assignment from the shield to the controller.

I recommend using jumper wires to jump the shield to your controller matching what the controller is defaulted to using. if for anything else just to test and verify it is or is not working. I really think your problem is just a issue with pin assignment since the code does work on some hardware setups and not others

basically if the uno defaults to CS being on pin 10, jump pin 9 on the shield to pin 10 on the controller. then declare your CS pin as pin 10. (the shields wont care as long as its wired right all the declarations are for the controller to send info to the correct pin. then wire up your miso mosi and clk respectively and give it a go