Problem using ICSP/SPI 6-pin header on DUE to interface with SD Card

All,

I am trying to use the 2GB MicroSD shield (found here: http://www.cooking-hacks.com/index.php/microsd-2gb-module-for-arduino.html) with the Due through the ICSP/SPI header. It works with my Uno using the regular digital pins but not through the ICSP/SPI 6 pin port on the Uno. I have not been able to get it to work at all with my DUE and am afraid of using the digital pins because of the 5V vs 3.3V used by the SPI interface. Ultimately, I want this to work on the Due and don’t care if it works with the Uno. I’ve found a spot (lines 71-81) in the Sd2Card.h file which is used in the SD.h library. I have edited it as shown bellow but it still does not work. By work, I mean it still does not initialize the SD card. Please help.

#else  // SOFTWARE_SPI
// define software SPI pins so Mega can use unmodified GPS Shield
/** SPI chip select pin */
uint8_t const SD_CHIP_SELECT_PIN = 10;
/** SPI Master Out Slave In pin */
uint8_t const SPI_MOSI_PIN = ICSP 4; //was 11 ICSP4
/** SPI Master In Slave Out pin */
uint8_t const SPI_MISO_PIN = ICSP 1; //was 12 ICSP1
/** SPI Clock pin */
uint8_t const SPI_SCK_PIN = ICSP 3; //was 13 ICSP3
#endif  // SOFTWARE_SPI

I believe that if I change which pin the variable in the file points to then I will still be able to use all of the other functions of that library which use the variables I changed the pin locations of. I am not sure how to reference the pin locations of the ICSP header.

Bellow is the code I’ve been using to test this:

/*
  SD card datalogger
 
 This example shows how to log data from three analog sensors 
 to an SD card using the SD library.
 	
 The circuit:
 * analog sensors on analog ins 0, 1, and 2
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 
 created  24 Nov 2010
 modified 9 Apr 2012
 by Tom Igoe
 
 This example code is in the public domain.
 	 
 */

#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 = 10;
//int pow_pin = 8; //for when on digital Uno pins

void setup()
{
  //  pinMode(pow_pin, OUTPUT); //for when on digital Uno pins
//  digitalWrite(pow_pin, HIGH); //for when on digital Uno pins
 // 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(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
}

void loop()
{
  // make a string for assembling the data to log:
  String dataString = "";

  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 2) {
      dataString += ","; 
    }
  }

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  } 
}

Many thanks,
SW

I was having a similar problem. I found this in my travels.

Link