sd card failed to initialize

The USBDroid provides USB Host functionality for use as an Android peripheral as an Open Android Development Kit board. [Product page]
Post Reply
haveachillday
Posts: 6
Joined: Thu Sep 03, 2015 4:51 am

sd card failed to initialize

Post by haveachillday » Sun Oct 18, 2015 10:37 pm

When I use sd.begin with the sd and spi libraries, it returns a false value indicating failed to initialize. im not sure what this means; has anyone run into this?

my 4gb SD card is formatted to fat 32 with the manufacturers program. I could try a two gigabytes fresh SD card and see if it changes anything. others on google mention the size of the card increases the time taken to initialise, i used the droid's ss pin as chip select and defined it as output as the arduino page on sd mentions it wont work without.

i have a hunch that the sd library is designed for external sd shields and not the in built mount of the droid. any thoughts guys?

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: sd card failed to initialize

Post by andrew » Sun Oct 18, 2015 11:29 pm

SD library is fine with the USBDroid, however for larger cards use the SdFAT library by Bill Greiman:
https://github.com/greiman/SdFat
Again, don't forget to change the SS pin to D10.

haveachillday
Posts: 6
Joined: Thu Sep 03, 2015 4:51 am

Re: sd card failed to initialize

Post by haveachillday » Mon Oct 19, 2015 3:28 pm

SD.begin is now indicating the card is working proper thanks to a switch to SDFAT. however, the tmrpcm library still wont output music. It does output a pop every time the play function is called and my speaker set up has already passed tests. sorry to lay the extra info on you im just rubbering ducking on two forums at once!

I've had a hunch since I heard the uno has only two timers. I found something interesting in the TMRpcm.cpp file in the tmrpcm library. On line 231 it mentions in a comment that if speaker pin set to 6, which is true in my case, program will use timer 4... which doesnt exist. I changed it to use timer 1 and now every time I press the a play button the d12 on board led starts flickering, for about a minute, then stops. When I revert line 231 back to default, it will no longer flash. I'm close enough to taste success! :) but still stuck. :o maybe im hogging an spi pin?

*EDIT* the led lit time is exactly the time taken to play the file!! but no output. ill double check my speaker pin and output scheme tomorrow since it seems the music is playing.

Almost forgot, i had this the whole time.

Code: Select all

#define SDChipSelectPin 10  //we use this pin as a sensor to detect if sd card is present.
  pinMode(10, OUTPUT);         //chip select pin for spi must be a constant output.

Code: Select all

if (!SD.begin(SDChipSelectPin)) 
  {
    Serial.println("Can't detect sd card.");  //check the sd card is working.
    while (true);
  }
  Serial.println("SD card detected.");
  Serial.print("Initializing SD card...");
  
  if (!SD.begin()) {
    Serial.println(" Failed!");
    while (true); //end program at the error.
  }
  Serial.println(" SD card initialized.");
  Serial.print("reading file...");
  
  if (!SD.open("sound1.wav"))
  {
    Serial.println(" could not open file.");
    while (true);  //end program at the error. 
  }
  Serial.println(" file opened; all tests succeeded!");
SD card detected.
Initializing SD card... SD card initialized.
Reading file... File opened; All tests succeeded!

Post Reply