SdFat for Due posted

Hi Simon,

However I get an "initialization failed" error message from the code, which means that the DUE failed to write to the SD card. After reading several documentations, I suspect that pin 4 and 10 are indeed the right ports to read/write, but I could be wrong...

There "initialization failed" error message does NOT mean the DUE failed to write to the SD card, it did not even get past initialization.......

"I suspect that pin 4 and 10 are indeed the right ports to read/write", clearly you have misunderstood how SPI access to the SD card works, MISO/MOSI are the data in/out ports and are NOT pins 4 or 10. You should read up some more about SPI SPI - Arduino Reference but in a nutshell, the gist of it is this, you have a clock, data in and data out which go to ALL SPI devices, the only pin that changes and thus allows you to access a specific device is the CS(SS) pin

There are a couple of things you need to check.

Taken from "DUE_Shield_readme.txt"

Shipping default jumper configuration:

The TFT/SD Shield for arduino DUE is shipped with the following jumper config, if you use TFT modules in our store, you do not need to reconfig the jumpers.

LCD Vcc - 3.3V (JP2 shorted)
LCD backlight (LEDA+) - 3.3V (JP4 shorted)
arduino Pin32 to TP_DIN (JP10 opened)
On board SD - disabled (JP8 opened)

NOTE JP8 opened/on board SD - disabled. !!!!! Did you put a solder blob on JP8?

Assuming you did, the next thing to check is that you changed both entries relating to CS(SS) in your SD code :-

  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
   pinMode(10, OUTPUT);
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

As a self-confessed newbie, did you pick up on the misleading error in the example??

pinMode(10, OUTPUT); & if(SD.begin(4)) { ??

The 10, and 4 relate to the same pin and therefor SHOULD at least be the same, in your case 53!

The coldtears shield is exactly what I have if you read the very post before yours, and it works fine with both SD and SDFATLIB once you bridge JP8, and use pin 53 as SS.

Best wishes,

Graham

Hi Graham,

Thanks for the suggestions. I would not have realized the need for soldering on JP8 or the what the code meant if you hadn't pointed it out for me. I've made a solder blob to enable JP8, and I also tried to use 4, 10, 52 and 53 to SS pin (keeping the numbers consistent for lines "pinMode(10, OUTPUT);" and "if(SD.begin(10))".) However I'm getting the same results as before... "Initialization failed." ...The only ideas I can come up with at the moment is that maybe my shield is busted, or perhaps I need a different library? I have SD.h for now, and I'm not sure how I can get SDfat library.

Please let me know if you have any more suggestions. Thanks again.

-Simon

simonc319:
I have SD.h for now, and I'm not sure how I can get SDfat library.

Please let me know if you have any more suggestions. Thanks again.

-Simon

Hi Simon,

You can look here for sdfatlib Google Code Archive - Long-term storage for Google Code Project Hosting..

The only other comments I have is that there is always the possibility the SD card you are using is a bit naff? I had a cheap ebay job that would not work with SD.h but did work with sdfatlib at slow speed.

Finally, did you try the 'CardInfo' example? This should tell you at least that the card is detected and wiring is correct, it will also initialize with SPI_HALF_SPEED by defualt, which will go some way towards proving if the SD card is not so good.

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

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3518857216
Volume size (Kbytes): 3436384
Volume size (Mbytes): 3355

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

You do NOT need to bother 'trying' 4,10,52 as your SS pin...............on the coldtears shield it IS 53 !! PERIOD.

If this still does not help you, beg/steal/borrow a different SD card, preferably SanDisk, Transcend, Kingston ..... even only 1GB or 2GB at least until you are confident of your hardware and software arrangement.

Regards,

Graham

I have a Breakout Board for microSD Transflash from SparkFun (SparkFun microSD Transflash Breakout - BOB-00544 - SparkFun Electronics) and I am trying to connect it to the Arduino Due I just bought.

I read this entire forum and countless others and still can not figure out what i am doing incorrectly. I connected the DO (MISO), SCK, and DI (MOSI) to the correct pins on the SPI 6 pin male connector. I used The 21st Century Digital Home: Arduino Due Hardware SPI to configure the pins.

I also attached my chip select (CS) to digital pin 52 to make use of the extended SPI.

5V into Vcc and GND into GND. CD is not connected on my breakout board.

I just used the standard READWRITE example for the SD that comes preloaded in the arduino IDE.

Can someone please explain why I am getting "initialization failed"?? Purely from the print statements that it is because SD.begin(52) does not work. I am confused by this. However, I tried so many more digital pins because lots of people said it doesn't matter, but no luck.

Please help!

/*
  SD card read/write

 This example shows how to read and write data to and from an SD card file
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4

 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 */

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

File myFile;

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


  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  
  //pinMode(52, OUTPUT);

  if (!SD.begin(52)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("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");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
  // nothing happens after setup
}

Hi ArdunioDetection.

I have a Breakout Board for microSD Transflash from SparkFun (SparkFun microSD Transflash Breakout - BOB-00544 - SparkFun Electronics) and I am trying to connect it to the Arduino Due I just bought.

Those things are notoriously difficult to get working first time, especially if you are new to all of this! The first and most common problem is connecting wires that are too long, and personally I like the to have the wires the same length too.

5V into Vcc and GND into GND

????????!!!!!!! 5V into Vcc!!!!!!!!!???????

You may actually have destroyed your SD card..... You SHOULD NOT be using 5V with an SD card!! They are all 3.3V for supply and signal level!!

I read this entire forum and countless others and still can not figure out what i am doing incorrectly.

You read this entire forum but chose to ignore my post immediately prior to yours?

You can look here for sdfatlib Google Code Archive - Long-term storage for Google Code Project Hosting..

The only other comments I have is that there is always the possibility the SD card you are using is a bit naff? I had a cheap ebay job that would not work with SD.h but did work with sdfatlib at slow speed.

Finally, did you try the 'CardInfo' example? This should tell you at least that the card is detected and wiring is correct, it will also initialize with SPI_HALF_SPEED by default, which will go some way towards proving if the SD card is not so good.

One final comment, I notice from your code you commented out the pinmode statement.

// or the SD library functions will not work.

//pinMode(52, OUTPUT); <---------- ?? Uncomment this!!!

if (!SD.begin(52)) {
Serial.println("initialization failed!");
return;

Assume your SD is now dead after its exposure to 5V, so test in another device or get another card before you go any further.

Try my suggestions, and post back how you get on.

Regards,

Graham

Hi,

I've just tried bench.ino from the SDFat Beta (Dec. 2014) and using a simple SD card module from Ebay and also an Arduino Due. The SD card is a Transcend 16GB Class 10 formatted with FAT32 using the SD formatting tool from sdcard.org, but copied some file on it.

I just can use the SPI_HALF_SPEED, I'll get errors with SPI_FULL_SPEED.

This is the result:

Free RAM: 94075
Type is FAT32
Card size: 15.93 GB (GB = 1E9 bytes)

Manufacturer ID: 0X3
OEM ID: SD
Product: SL16G
Version: 8.0
Serial number: 0X80E4DD27
Manufacturing date: 8/2014

File size 5 MB
Buffer size 512 bytes
Starting write test, please wait.

write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
375.92,58303,798,1354
372.03,38391,1072,1367
372.06,38406,1058,1367
370.59,38381,1055,1372
371.14,39037,1059,1370
371.14,38390,1056,1370
371.64,38387,1071,1368
371.06,38388,1071,1370
370.70,39672,1059,1371
371.42,38398,1057,1368

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
1178.89,866,423,432
1178.89,867,415,432
1178.61,866,416,432
1178.61,867,416,432
1178.61,867,416,432

Done

But sometimes when I start the sketch I'll get this error:

Can't access SD card. Do not reformat.
No card, wrong chip select pin, or SPI problem?
SD errorCode: 0X1,0X0

without changing anything. Turning off the Arduino IDE and the Arduino (cycle power) may fix this problem.

Any idea?

Best regards
Nils

Shorten your connecting wires as much as you possibly can and try to use all the same length. I would expect this to allow you to be able to use SPI_FULL_SPEED and probably get rid of your random no card errors too.

Regards,

Graham

Hi,

the wires length is about 20cm / 8 inches. I often get this problem also with SPI_HALF_SPEED.
The speed is currently not the big deal, I just try to get some data from the SD card.

The file SdInfo.h contains some constants for the SPI speed. Also with SPI_SIXTEENTH_SPEED I get errors...

Is the only way to get this work using short wires?

Best regards
Nils

derniwi:
Is the only way to get this work using short wires?

Obviously short wires would be best.

If you can't do that, at least try to group the wires together closely, minimizing the area in the loop formed between any signal and the GND wires. The ideal physical wiring is a GND wire tightly twisted with each signal, with all GND wires connected to the GND pins on both the Due and SD card.

The other thing you can try is adding series termination resistors on the 4 signals. Values between 47 to 220 ohms are probably about right, though the specifics depend on the type and spacing of your wires. The wire used in CAT6 cable is designed for exactly 100 ohms.

These issues are common with the WS2812 (aka NeoPixel) LEDs, where a digital signal from a pin is run quite some distance from the pin to the LED strip. On my OctoWS2811 library page, scroll down to the "Signal Quality" section for more info, and some oscilloscope screenshots that show the issue with a real signal.

@Paul: I have some "old" CAT6 wires (broken connectors or something like this) so it should be possible to use them for connecting and use 100 ohm terminator resistors? I haven't used term. resistors since I gave up using SCSI devices... ;D

I would appreciate some help with the SdLibrary.

Software: I loaded it to the Due with the benchmark program, and set the CD pin to 10.

Hardware: MISO, MOSI, SCK are all connected to the proper SPI pins on the Due. it does NOT have level shifting, it only has 10K pull up resistors to the 3.3V bus. Also, while the card holder has it's own 3.3 volt regulator, I bypassed that and connected the 3.3 volt pin directly to the Due's 3.3 volt pin. Of course GND is connected, and CS to pin 10. All the wiring is short, can't be more than 3 inches.

While read latency seems ok (average 83 us), the write latency is horrific: 3470 us. Average write speed is under 30 KB/s.

The card is a run-off-the-mill 2GB Kingston card.

Any hints would be greatly appreciated!

Free RAM: 93235
Type is FAT16
File size 5MB

Buffer size 100 bytes

Starting write test. Please wait up to a minute

Write 28.80 KB/sec

Maximum latency: 195699
usec, Minimum Latency: 5
usec, Avg Latency: 3470 usec

Starting read test. Please wait up to a minute
Read 1169.59 KB/sec

Maximum latency: 2741
usec, Minimum Latency: 5
usec, Avg Latency: 83 usec

@SdFatLib: can you point me to the best of your libraries for Due, please sir.

I have found these but am not sure which to choose:

  1. Google Code Archive - Long-term storage for Google Code Project Hosting.
    This is only one I've found that includes ArduinoDue.txt but is a bit old? (June 2013)

  2. GitHub - greiman/SdFat-beta: Beta SdFat for test of new features

or is it now merged into your standard SdFafLib:

  1. GitHub - greiman/SdFat: Arduino FAT16/FAT32 exFAT Library

or:

  1. none of your libs support Due any more? :frowning:

TIA

Option 3.

G

tks G

Assuming I wire the SD correctly for DUE, should code that ran SD OK on a Mega work for Due without any modifications?

Syntax wise there is no difference. But the DUE with sdfat has a clever DMA system that really helps speed things up somewhat! 8) ;D (As long as further down the road you don't also want to use Ethernet!)

G

OK good.
Do I need to modify my code to get benefit of the DMA speed, or will it do that for me automagically using Mega code?

No.

G

Hi! I've tried 3 different SD card socket . 2 are just SD card holders and one is a catalex module on 3.3. Nothing works and every connection is in its own place. Do I need something more to get the thing running on Arduino due? Thank you

Follow this thread, reply #3 :

https://forum.arduino.cc/index.php?topic=411233.0

Do you think it is library wise?