3

I'm trying to read from the SD card using an Arduino Pro Mini (3.3 V), Pololu micro-SD reader (the 3.3V one) over a SPI protocol.

I've tried both the SD library from Arduino SDK, and the Adafruit one.

Connections:

  • Arduino pin 10 -> CS,
  • pin 11 -> DI
  • pin 12 -> DO
  • pin 13 -> SCLK.

I've also connected VCC and GND of course.

This call (from the DumpFile example) fails:

// I've tried SD.begin(), SD.begin(10) as well.
if (!SD.begin(10, 11, 12, 13)) {
  // I can see this print statement in serial monitor.
  Serial.println("Card failed, or not present");
  return;
}

I've also tried manually setting pin 10 to OUTPUT, as well as to set it to HIGH.

Now, with the Adafruit SD library, I investigated this issue a bit more. It seems, that SD.begin() invokes the card.init(SPI_HALF_SPEED, csPin, mosi, miso, sck) (of the Sd2Card class).

I added print statements and discovered this exact piece fails:

while ((status_ = cardAcmd(ACMD41, arg)) != R1_READY_STATE) {
    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
     // This is being printed.
     // status_ is 1
     Serial.println("init err here!");
     Serial.println(status_);
     error(SD_CARD_ERROR_ACMD41);
      goto fail;
    }
}

I've prepared a card (2GB one) - it's FAT16 formatted, and contains one partition. On this partition there's a single file ony, named "a.txt".


EDIT: After trying another SD card, I got some progress. Now, the following call fails:

volume.init(card) // in SD.cpp

After digging in, I discovered that this invokes the cacheRawBlock(volumeStartBlock, CACHE_FOR_READ), which invokes sdCard_->readBlock(blockNumber, cacheBuffer_.data) and then Sd2Card::readData(block, offset, count, dst).

In readData(), the following fails:

if (!inBlock_ || block != block_ || offset < offset_) {
    block_ = block;
    // use address if not SDHC card
    if (type()!= SD_CARD_TYPE_SDHC) block <<= 9;
    if (cardCommand(CMD17, block)) {
      // ****************************
      // FAIL IS HERE - cardCommand(CMD17, block) fails.
      // ****************************
      error(SD_CARD_ERROR_CMD17);
      Serial.println("SD_CARD_ERROR_CMD17");
      goto fail;
    }
    if (!waitStartBlock()) {
      goto fail;
    }
    offset_ = 0;
    inBlock_ = 1;
}

What the issue can possibly be?

VE7JRO
  • 2,497
  • 15
  • 24
  • 29
kamituel
  • 141
  • 4
  • Have you tried a different SD card? – Majenko Jul 10 '15 at 21:45
  • `if (!SD.begin(10, 11, 12, 13)) {` - that does not compile. `expects 1 argument, 4 provided`. Please post the entire sketch you tried, which compiles, but does not successfully open the card. Also try another card, you must have another SD card lying around. Internally some of them work better than others, connected to the Arduino. – Nick Gammon Jul 10 '15 at 21:54
  • The `SD.begin(10,11,12,13)` works with Adafruit SD library. Anyway. I just tried it with a different SD card (FAT-32 this time, 4GB) and I got some progress! Now it fails on `volume.init(card)` call. I'll update the question in a second. – kamituel Jul 10 '15 at 21:58
  • Sounds like you were using a cheap (Chinese, eBay) card that doesn't support the SPI protocol. Works fine on a PC with SDIO but not an Arduino on SPI. – Majenko Jul 10 '15 at 22:45

0 Answers0