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,515
  • 19
  • 27
  • 29
kamituel
  • 141
  • 4

0 Answers0