Arduino Due SD Card Reader Performance

Hi All,

Been doing some experiments with an Arduino Due hooked up to a 3rd party SD Card reader and I thought others may find it useful.

I placed a 2.6mb wav file on a 2gb SD card, then proceeded to try a number of buffer sizes and settings to determine what the Due's SD/SPI is really capable of.

Opening the file and reading byte by byte was accomplished in 19 seconds
Creating a buffer of 400 bytes (deliberate mismatch to file block size) got me to approx 8.5 seconds
Making the buffer 1024 bytes reduced the time by about 1 second (which was disappointing I thought)
Making the buffer any larger had no meaningful effect on performance
I then experimented with modifying the clock divider for the SPI. I believe the default is 4 and my tests seemed to support this.
Making the divider 2 gives me a healthy 5 second time - thats over half a mb per second! (definitely fast enough for the planned audio work)
I finally tried a divider of 1, but that just crashed the card I was using - assume it was too fast!

BTW - also have verified the SD library is quite happy to have more than one file open simultaneously (There seemed to be conflicting posts when I did a search)

Hope this helps!

Here is the code I used as it was at the end of the testing - (I used the SD example as the basis for my code)

/*
  SD card file dump

 This example shows how to read a file from the SD card using the
 SD library and send it over the serial port.

 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4

 created  22 December 2010
 by Limor Fried
 modified 9 Apr 2012
 by Tom Igoe
modified 6 August 2014
by Chris Draper

 This example code is in the public domain.

 */

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

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 4;
  File dataFile1;  
 
   
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...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(chipSelect, OUTPUT);
  //pinMode(10, OUTPUT);

  // see if the card is present and can be initialized with default bit order of MSBFIRST:
  if (!SD.begin(chipSelect)) {
    //Failed - but card may be LSBFIRST so try again:
    SPI.setBitOrder(LSBFIRST);
     if (!SD.begin(chipSelect)) {
        //Give Up
        Serial.println("Card failed, or not present");
      // don't do anything more:
      return;
     }
  }
  Serial.println("card initialized.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  

 
  uint8_t buf[1024];

    // hi-speed SPI transfers for Due only
    SPI.setClockDivider(2);
  // if the file is available, write to it:
   dataFile1 = SD.open("dft.wav");
   if (dataFile1) {
      Serial.println(millis());
     
      while (dataFile1.available()) {
      dataFile1.read(buf,sizeof(buf));

    }
    Serial.println(millis());
    dataFile1.close();


    Serial.println("Read Completed");
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening file");
  }



}

void loop()
{
}