Atmega1284p not finding SD Card. (Do you have a working sketch?)

My SD Card was working great with the Atmega328p, but not after I upgraded to Atmega1284p.

I know the AVR's SPI is working because it runs the LCD Display perfectly.

Things I've tried are:

  1. Checked continuity of all jumper wires.
  2. Checked that all connections are correct
  3. Tried with a different SD Card and holder.
    4 Checked that the software names the pins correctly.
  4. Verified "defined(AVR_ATmega1284P)" is in the "Sd2PinMap.h" file.
  5. Tried with <SD.h> on an included example.
  6. Tried with <SdFat.h> simulating <SD.h> on an included example.
  7. Tried with pure <SdFat.h> on an included example.

In all cases, I see "SD initialization failed!".

Probably the best idea is if someone HAS their SD Card working on an Atmega1238p, and can send me a working sketch with the library they've used, so I can start with what is known to work, and modify back from there.

If you can do this, thanks a million!

Sure,
Try the code for this programmer card. I ran it in on a 1284P also while working up this design.
http://www.crossroadsfencing.com/BobuinoRev17/Programmer.html

Thanks for the idea, Crossroads. The software you suggested installed without a single error message. But when it got down to line 1280,

while (!sd.begin (chipSelect, SPI_HALF_SPEED))

The function "sd.begin" continued returning "FALSE", which has been my problem all along.

I suspect there may have been some adjustments to the software you suggesgted, since it's now being used with different hardware.

So I'm still in need of a simple sketch with library, that's proven to work with the Atmega1284p and SD Card, exactly as is.

Here's an interesting bit of info:

bratan:
... I tried these bootloaders on same 1284p chip and here's result:

  • Mighty 1284 w/ Optiboot: RF12B Module works. SD card doesn't work
  • Bobuino: RF12B Module Doesn't work ... SD Card Doesn't work
  • Sanguino 1284 : RF12B Module doesn't work. SD Card WORKS!

...

I'm using the "Mighty 1284 w/ Optiboot", which the above says "doesn't work". Does this relate to my problem? What could be so marginal that choice of bootloaders could cross over the line?

CosmickGold:
Here's an interesting bit of info:

I'm using the "Mighty 1284 w/ Optiboot", which the above says "doesn't work". Does this relate to my problem? What could be so marginal that choice of bootloaders could cross over the line?

I got it working with Mighty Optiboot.
If I remember correctly it was some pin definitions in the bootloader files. There's no standard for those. One bootloader can use physical pin 30 as D2 another one will use it as D15 (I'm making up those numbers) for example...

Thank you, Bratan. At least I now know its possible to get "CD Card" & "1284p" & "Mighty Optiboot" all working together. I just have to figure out how.

Your "working" link above is broken. I'm hoping you'll fix it, and it will lead to a sketch that solves my problem!

It makes sense what you said about "pin definitions" having no standard. So I wrote this little program, allowing me to enter data pin numbers one-at-a-time into Arduino's "Serial Monitor", and use an LED to see which physical pin started flashing in response.

// *** PIN TESTER ***

char c;
byte n = 0;

void setup()
{
  Serial.begin(9600);
  for (byte i=0; i<32; i++)
    pinMode(i, OUTPUT);
}

void loop()
{
  if (Serial.available())
  {
    c = Serial.read();
    n = (c - 48) * 10;
    delay(2);
    c = Serial.read();
    n += c - 48;
    Serial.println(n);
  }
  //for (byte i= 0; i<32; i++)
    digitalWrite(n,HIGH);
  delay(1000);
  //for (byte i= 0; i<32; i++)
    digitalWrite(n,LOW);
  delay(1000);
}

The result: All 32 data pins -- D0 through D31 -- are as shown on this diagram for Mighty Optiboot:

I also checked the four SPI constants with:

  Serial.print("SS:");
  Serial.print(SS);  
  Serial.print("  MOSI:");
  Serial.print(MOSI);  
  Serial.print("  MISO:");
  Serial.print(MISO);  
  Serial.print("  SCK:");
  Serial.println(SCK);

which correctly reported:

"SS:4 MOSI:5 MISO:6 SCK:7"

Then I made sure Mighty Optiboot's patched copy of "SD.h" (along with the other patched libraries) are running in my user "Arduino/hardware" folder.

So I think all the above rules out a pin-numbering mismatch being my problem.


So, next, I'm wondering if the SPI clock speed could be too fast for my SD Card?

On the AVRFREAKS forum, I found:

Everything works alright when SPI clock is 1MHz....
But when I turn to SPI clock = 2MHz or higher the SD card won't even initialize,
...
...stray/input capacitance might case it to fail at higher speeds.

And then I found in an Application Note:

SD cards require a specific initialization sequence....
Card initialization starts by setting the SPI clock to 400kHz....
Finally, the SPI clock is set to the maximum rate allowed.

I assume SPI.begin() is doing all the above, but what is this "maximum rate allowed"? I should drop that to the 1MHz mentioned above and try my SD Card again.

So I went to Arduino's SPISettings page, and read that I should be able to set the SPI clock speed with either

SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0))

or

SPI.SPISettings mySettting(1000000, MSBFIRST, SPI_MODE0)

But the compiler couldn't find either of those functions, giving the messages,

'class SPIClass' has no member named 'beginTransaction'

and

'class SPIClass' has no member named 'SPISettings'

So I'm still stuck.

Can someone tell me how to successfully change the SPI clock maximum speed, so I can see if this is what will allow my SD Card to work?

Sorry, I fixed the link.
Try a different SD card library. I'm using that that came with WaveShield. I had issues with others... It also let's you change speed I believe...

Finally! I got the SD Card working, after two, full, exhausting days!

Branton's suggested library didn't work for me, even though it had worked for him. That was helpful by letting me know it wasn't a software problem after all, and I needed to look in another direction.

Turns out, there were THREE hardware problems, each keeping me from recognizing the other two:

(1) I bought cheap Arduino-style jumper cables from China; and although they looked good, about 15% of them had no electrical connection end-to-end! Gasp! (That's what I get for being such a "penny pincher". While true Arduino means Quality!)

(2) The SD Card I was testing with wasn't even formatted! (Duhh!)

(3) The power/ground connections were passing through so many jumpers across the board, they had way too much digital noise, along with major voltage loss along the journey.

Each one of those things -- by itself -- was making the SD Card completely not work.


Thank you, Branton, for your truly helpful messages; both teaching me new things, and pointing me in the right direction.