Hello,
I'm trying to use USE_SOFTWARE_SPI mode in the SdFat library. I had gotten the SD card to work just fine using the Arduino Due's SPI lines, but ran into some trouble running both the SD card and another device (FLASH memory) on the same SPI bus. I realize that SPI using digital pins will be slower, but I thought I'd give it a shot.
But... sadly it isn't working. I'm getting the error:
use software spi: 1
Can't access SD card. Do not reformat.
No card, wrong chip select pin, or SPI problem?
SD errorCode: 0X1,0XFF
I followed these instructions:
Define MEGA_SOFT_SPI to be non-zero in SdFatConfig.h to use software SPI
on Mega Arduinos. Pins used are SS 10, MOSI 11, MISO 12, and SCK 13.
I've hooked up my SD card module as follows:
SD card => Arduino
CS => pin 10
DI => pin 11
DO => pin 12
CLK => pin 13
My code is a slightly modified version of the read/write sample code:
#include <SdFat.h>
SdFat sd;
SdFile myFile;
void setup()
{
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
//while (!Serial) {} // wait for Leonardo
// Serial.println("Type any character to start");
// while (Serial.read() <= 0) {}
delay(400); // catch Due reset problem
Serial.print("use software spi: ");
Serial.println(USE_SOFTWARE_SPI);
// Initialize SdFat or print a detailed error message and halt
// Use half speed like the native library.
// change to SPI_FULL_SPEED for more performance.
if (!sd.begin(10, SPI_EIGHTH_SPEED)) sd.initErrorHalt();
// open the file for write at end like the Native SD library
if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
sd.errorHalt("opening test.txt for write failed");
}
// if the file opened okay, write to it:
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
// re-open the file for reading:
if (!myFile.open("test.txt", O_READ))
{
sd.errorHalt("opening test.txt for read failed");
}
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
int data;
while ((data = myFile.read()) >= 0) Serial.write(data);
// close the file:
myFile.close();
}
void loop() {
// nothing happens after setup
}
Any suggestions?
Thanks,
Bret