arduino-libraries / SD

SD Library for Arduino

Home Page:http://arduino.cc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adafruit SD card breakout board | SD card init failed

TinManAkshay opened this issue · comments

We have a custom board with ATSAMD51 microcontroller as a host. We've Lora chip connected to it via SPI. We have got one more SPI connector which I used to connect the micro sd card breakout board. I customized variant.h file to support SERCOM5 SPI pins. I've attached the pic for your reference.

customized variant

While I was trying to initialize the card, it always sd card init failed. Any help would be highly appreciated. Code is written below:

#include <SPI.h>
#include <SD.h>

SPIClass tinmanSPI(&sercom5, PIN_SPI_MISO, PIN_SPI_SCK, PIN_SPI_MOSI, SPI_PAD_3_SCK_1, SERCOM_RX_PAD_0);

File myFile;
Sd2Card card;
SdVolume volume;

void setup() {
  Serial.begin(115200);
  delay(1000);

  Serial.print("Initializing SD card...");
  //pinMode(42, OUTPUT);
  digitalWrite(SS, HIGH);

  if (!card.init(SPI_HALF_SPEED, SS)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card inserted?");
    Serial.println("* is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    Serial.println("Note: press reset button on the board and reopen this Serial Monitor after fixing your issue!");
    // while (1);
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.println();
  Serial.print("Card type: ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    //while (1);
  }


  while (!SD.begin()) {
    Serial.println("SD card initialization failed!");
    //return;
  }
  Serial.println("SD card initialization done.");

  /*
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  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");
  }
  */
}

void loop() {}

Hi @TinManAkshay. Thanks for your interest in this open source project. This issue tracker is only to be used to report bugs or feature requests specific to the project. This topic is more appropriate for the Arduino Forum. I'm sure we will be able to help you out over there:

https://forum.arduino.cc/