Hi
I have purchased sd card reader/writer and I'm currently trying to interface with it using the recommended library. I have an SD card installed. At the moment, I'm just trying to connect to the device to ensure that everything is working ok.
When I try the cardinfo example with chipSelect = 10 (which the documentation says is the correct chip select pin to use), the interface returns a failure:
#include <SPI.h>
#include <SD.h>
Sd2Card card;
SdVolume volume;
SdFile root;
int chipSelect = 10;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
delay (2000);
Serial.print("\nInitializing SD card. Trying Chip Select ");
Serial.println(chipSelect);
if (!card.init(SPI_HALF_SPEED, chipSelect))
{
Serial.println("initialization failed.");
}
else
{
Serial.println("Wiring is correct and a card is present.");
}
}
This produces the following output:
Initializing SD card. Trying Chip Select 10
initialization failed.
Just to make sure that I wasn't using the incorrect chipSelect pin I thought I would loop through each pin:
#include <SPI.h>
#include <SD.h>
Sd2Card card;
SdVolume volume;
SdFile root;
int chipSelect = 0;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
delay (2000);
while (true)
{
Serial.print("\nInitializing SD card. Trying Chip Select ");
Serial.println(chipSelect);
if (!card.init(SPI_HALF_SPEED, chipSelect))
{
Serial.println("initialization failed.");
}
else
{
Serial.println("Wiring is correct and a card is present.");
}
chipSelect++;
}
}
and to my suprise the output was as follows:
Initializing SD card. Trying Chip Select 0
initialization failed.
Initializing SD card. Trying Chip Select 1
initialization failed.
Initializing SD card. Trying Chip Select 2
initialization failed.
Initializing SD card. Trying Chip Select 3
initialization failed.
Initializing SD card. Trying Chip Select 4
initialization failed.
Initializing SD card. Trying Chip Select 5
initialization failed.
Initializing SD card. Trying Chip Select 6
initialization failed.
Initializing SD card. Trying Chip Select 7
initialization failed.
Initializing SD card. Trying Chip Select 8
initialization failed.
Initializing SD card. Trying Chip Select 9
initialization failed.
Initializing SD card. Trying Chip Select 10
Wiring is correct and a card is present.
Clearly chipSelect = 10 is succeeding when looping through...but not when I hardcode the chipSelect = 10. What am I missing here!?
EDIT: I have also added 'pinMode(chipSelect, OUTPUT)' and 'digitalWrite(chipSelect, HIGH)' which others have recommended but unfortunately it is still not working.
Thanks