Failing SD Card Initialization with Feather M0 LoRa

Hello,

I am using the Micro SD Card Breakout Board along with my Feather M0 LoRa for datalogging.

I am using the example script, CardInfo, provided with the SD library to test to see if it is working properly. I have edited the script with the proper pinouts and I keep getting this error:

Initializing SD card...initialization failed. Things to check:
* is a card inserted?
* is your wiring correct?
* did you change the chipSelect pin to match your shield or module?

Here's what I've done to troubleshoot the issue:

  • Tested the same SD card with three different SD card modules on the Feather
  • Tested a new, fresh out-of-the-box SD card with the same three SD card modules on the Feather
  • Used a working Arduino Mega to test two of the three SD card modules
  • With the Mega, switched between using 5V and 3.3V to see if power was an issue

For reference, here are the pin connections I used for the Feather

GND - GND on Feather
3v - 3v on Feather
CLK - SCK/pin 24 on on Feather
DO - MISO/pin 22
DI - MOSI/pin 23
CS - pin 13

Here are the pin connections I used for the Arduino Mega

GND - GND
3v - 3v/5v - 5v
CLK - pin 13 on Mega
DO - pin 12 on Mega
DI - pin 11 on Mega
CS - pin 10 on Mega

And here is the script I used:

/*
  SD card test

  This example shows how use the utility libraries on which the'
  SD library is based in order to get info about your SD card.
  Very useful for testing a card when you're not sure whether its working or not.

  The circuit:
    SD card attached to SPI bus as follows:
 ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
 ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
 ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
 ** CS - depends on your SD card shield or module.
 		Pin 4 used here for consistency with other Arduino examples


  created  28 Mar 2011
  by Limor Fried
  modified 9 Apr 2012
  by Tom Igoe
*/
// include the SD library:
#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
// MKRZero SD: SDCARD_SS_PIN
const int chipSelect = 10; //used 10 for the Mega, 13 for the Feather M0

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("\nInitializing SD card...");

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!SD.begin(chipSelect)) {
    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?");
    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);
  }

  Serial.print("Clusters:          ");
  Serial.println(volume.clusterCount());
  Serial.print("Blocks x Cluster:  ");
  Serial.println(volume.blocksPerCluster());

  Serial.print("Total Blocks:      ");
  Serial.println(volume.blocksPerCluster() * volume.clusterCount());
  Serial.println();

  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("Volume type is:    FAT");
  Serial.println(volume.fatType(), DEC);

  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize /= 2;                           // SD card blocks are always 512 bytes (2 blocks are 1KB)
  Serial.print("Volume size (Kb):  ");
  Serial.println(volumesize);
  Serial.print("Volume size (Mb):  ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Gb):  ");
  Serial.println((float)volumesize / 1024.0);

  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);

  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}

void loop(void) {
}

Hello,
Do you use by any chance an SD card which has more than 2Gbyte storage?
I had similar problems, seems that only upto 2Gbyte cards work properly.
regards,
Geert

Does it work on the Mega?

I used 8GB and 16GB SD cards when I was testing. I ordered a bunch of 2GB SD cards that'll be coming in today so I'll update the thread on whether it ends up working.

No, it did not work on the Mega

CLK and DI on the same pin of the Feather?

Wrong pins for the Mega; check the pinout diagram of the Mega; the SPI pins are on the 6-pin header in the center and on 50/51/52(/53).

For all those interested in this matter, see the next Youtube vid at around 3'15''
SD-Card with Arduinos - Common Problems and How to Fix 'em - YouTube
This person explicitly mentioned that a card above 2Gb will not work, because he tested it.
That's where I got the above mentioned information.
Hope to have helped some of you.
Regards,
Geert

1 Like

Thanks for the catch. I edited the post to have the proper pins I used. I redid the wiring on the Mega according to your instructions and I was able to write to the 2GB SD card using my Mega as @geert_borloo suggested!

I tried doing the same with the Feather but I got the same error as before. I found out from this post and this post that I have to change the CS signal pins from high and low based on the SPI device I want to talk to. Correct me if I'm wrong, but is this because they share the same SPI pins?

So in order to talk to the SD card module with my Feather, I added this right before initializing the SD card module

  digitalWrite(8, HIGH);
  digitalWrite(chipSelect, LOW);

where 8 is the CS pin for the built-in LoRa radio module. I now have this error:

Initializing SD card...Wiring is correct and a card is present.
Card type:         Unknown
Could not find FAT16/FAT32 partition.
Make sure you've formatted the card

I tried reformatting 3 of the 2GB SD cards I have into FAT16 and tested with that, but to no avail. I did the same with FAT32 but it still doesn't seem to work.

I did a bit more searching and found this post:

I tried reformatting the SD cards using the SD Formatter utility from the SD Association as opposed to the one built into my OS and it worked!

Initializing SD card...Wiring is correct and a card is present.

Card type:         SD2
Clusters:          61428
Blocks x Cluster:  64
Total Blocks:      3931392

Volume type is:    FAT16
Volume size (Kb):  1965696
Volume size (Mb):  1919
Volume size (Gb):  1.87

Files found on the card (name, date and size in bytes): 
SYSTEM~1/     2024-02-13 09:04:52
  INDEXE~1      2024-02-13 09:04:52 76

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.