Go Down

Topic: SD card...initialization failed Adafruit MicroSD (Read 34094 times) previous topic - next topic

CrossRoads

@jlsilicon,
You posted the same question in 4 places. I've deleted the duplicates. Please don't do that again. Post once, have a little patience for an answer.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

jlsilicon

#16
Nov 20, 2017, 12:35 am Last Edit: Nov 20, 2017, 05:52 am by jlsilicon
Do you have any idea - why the SdCards stats can be loaded , but stop at loading Files ?

Both cards were verified having Files on a SdCard Reader.

I even tried ReFormatting a Card in FAT16.

Program Results:

Code: [Select]

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

Card type: SD2

Volume type is FAT16

Volume size (bytes): 987938816
Volume size (Kbytes): 964784
Volume size (Mbytes): 942

Open Root:

Files found on the card (name, date and size in bytes):


- Does not List Files
- Does not Print out "Done"
- just Hangs.

I also backed out SD from 1.1.1 to 1.08 - same problem.

Is there a quirk, with CD ChipDetect - needed for Files, but not for SD Card Properties ?


jlsilicon

#17
Nov 20, 2017, 06:16 am Last Edit: Nov 20, 2017, 07:12 am by jlsilicon
Well, I seem to have found a/the problem:

I am using the SerialUSB.print() instead of Serial.print().

The root.ls() in the lib , prints to Serial.print() , no choice.
So, I used the SD.listfiles example.

It still returns No Files though.

But, it does exit now.

-

Code: [Select]

//  SerialUSB.println("\nOpen Root: ");
//  root.openRoot(volume);
//
//  SerialUSB.println("\nFiles found on the card (name, date and size in bytes): ");
//  // list all files in the card with date and size
//  root.ls(LS_R | LS_DATE | LS_SIZE);
//
//  root.close();


  root2 = SD.open("/");

  printDirectory(root2, 0);

  root2.close();


  SerialUSB.println("\n- done!");
}


void loop(void)
{
  ;
}


void printDirectory(File dir, int numTabs)
{
  while (true)
  {
    SerialUSB.println(".");

    File entry =  dir.openNextFile();
    if (! entry)
    {
      // no more files
      break;
    }
   
    for (uint8_t i = 0; i < numTabs; i++)
    {
      SerialUSB.print('\t');
    }
    SerialUSB.print(entry.name());
    if (entry.isDirectory())
    {
      SerialUSB.println("/");
      printDirectory(entry, numTabs + 1);
    } else {
      // files have sizes, directories do not
      SerialUSB.print("\t\t");
      SerialUSB.println(entry.size(), DEC);
    }
    entry.close();
  }

  SerialUSB.println("--");
}



Results now:

Code: [Select]


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

Card type: SD2

Volume type is FAT16

Volume size (bytes): 987938816
Volume size (Kbytes): 964784
Volume size (Mbytes): 942

Open Root:

Files found on the card (name, date and size in bytes):

.
--

- done !


But, where are the files ??
- Both SD Cards return No Files.

Seems to be getting stuck looping on the  first file (both Cards):
Code: [Select]

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

Card type: SDHC

Volume type is FAT16

Volume size (bytes): 3960733696
Volume size (Kbytes): 3867904
Volume size (Mbytes): 3777

Open Root:

Files found on the card (name, date and size in bytes):
FILE01.TXT   








- ???

jlsilicon

#18
Nov 20, 2017, 07:23 am Last Edit: Nov 20, 2017, 07:24 am by jlsilicon
Ok, Found it.

Typo, that I made in the Libs SdFile.cpp for root.ls() ,
  I pasted an  #endif  inserted on same line as w++,
    so it was ignored - yielding endless loop.

I added this, to fix the ArduinoZero/NanoArm print() to feed back to UsbProgrammer as SerialPort :

#ifdef SERIALUSB_E
  SerialUSB.print(...);
#else
  Serial.print(...);
#endif

-

Code: [Select]

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

Card type: SDHC

Volume type is FAT16

Volume size (bytes): 3960733696
Volume size (Kbytes): 3867904
Volume size (Mbytes): 3777

Open Root:

Files found on the card (name, date and size in bytes):
SDCARD4G.TXT  2017--19 18:38:46 10
FILE01.TXT    2017--19 18:38:50 0
FILE02.TXT    2017--19 18:39:00 0
FILE03.TXT    2017--20 00:11:54 0
DIR01/        2017--20 00:12:06

--

- done!


- don't understand why the PrintDir() func doesn't work though ... :

Code: [Select]

void printDirectory(File dir, int numTabs)
{
  while (true)
  {
    SerialUSB.println(".");

    File entry =  dir.openNextFile();
    if (! entry)
    {
      // no more files
      break;
    }
   
    for (uint8_t i = 0; i < numTabs; i++)
    {
      SerialUSB.print('\t');
    }
    SerialUSB.print(entry.name());
    if (entry.isDirectory())
    {
      SerialUSB.println("/");
      printDirectory(entry, numTabs + 1);
    } else {
      // files have sizes, directories do not
      SerialUSB.print("\t\t");
      SerialUSB.println(entry.size(), DEC);
    }
    entry.close();
  }

  SerialUSB.println("--");
}

oliverk996

I had this same problem until I realised I had not soldered the 2x3 female header....

Once I had done that it worked perfectly! LED SPI should light up red when there's no sd card installed.

Ran CardInfo with the chipset set to 10 and it worked perfectly.

Go Up