diff --git a/libraries/SD/SD.cpp b/libraries/SD/SD.cpp index 29b89c201..994473f40 100644 --- a/libraries/SD/SD.cpp +++ b/libraries/SD/SD.cpp @@ -319,21 +319,17 @@ boolean callback_remove(SdFile& parentDir, char *filePathComponent, -void SDClass::begin(uint8_t csPin) { +boolean SDClass::begin(uint8_t csPin) { /* Performs the initialisation required by the sdfatlib library. - Does not return if initialisation fails. + Return true if initialization succeeds, false otherwise. */ - // TODO: Allow chip select pin to be supplied? - if (!(card.init(SPI_HALF_SPEED, csPin) - && volume.init(card) && root.openRoot(volume))) { - while (true) { - // Bail - } - } + return card.init(SPI_HALF_SPEED, csPin) && + volume.init(card) && + root.openRoot(volume); } diff --git a/libraries/SD/SD.h b/libraries/SD/SD.h index c1cdbfbb9..33d944adb 100644 --- a/libraries/SD/SD.h +++ b/libraries/SD/SD.h @@ -20,9 +20,6 @@ #include #include -// Use this to configure the chip select pin of the SD card. -#define SD_CARD_CHIP_SELECT_PIN 4 // For use with Arduino Ethernet Shield - class File : public Stream { public: virtual void write(uint8_t); @@ -47,7 +44,7 @@ private: public: // This needs to be called to set up the connection to the SD card // before other methods are used. - void begin(uint8_t csPin = SD_CARD_CHIP_SELECT_PIN); + boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN); // Open the specified file/directory with the supplied mode (e.g. read or // write, etc). Returns a File object for interacting with the file. diff --git a/libraries/SD/examples/Files/Files.pde b/libraries/SD/examples/Files/Files.pde index dbcec71cf..b306793d4 100644 --- a/libraries/SD/examples/Files/Files.pde +++ b/libraries/SD/examples/Files/Files.pde @@ -6,7 +6,11 @@ void setup() { Serial.begin(9600); Serial.print("Initializing SD card..."); - SD.begin(); + // On the Ethernet Shield, CS is pin 4. + if (!SD.begin(4)) { + Serial.println("failed!"); + return; + } Serial.println("done."); if (SD.exists("example.txt")) Serial.println("example.txt exists."); diff --git a/libraries/SD/examples/ReadWrite/ReadWrite.pde b/libraries/SD/examples/ReadWrite/ReadWrite.pde index 5b05c6762..1267dce00 100644 --- a/libraries/SD/examples/ReadWrite/ReadWrite.pde +++ b/libraries/SD/examples/ReadWrite/ReadWrite.pde @@ -6,7 +6,11 @@ void setup() { Serial.begin(9600); Serial.print("Initializing SD card..."); - SD.begin(); + // On the Ethernet Shield, CS is pin 4. + if (!SD.begin(4)) { + Serial.println("failed!"); + return; + } Serial.println("done."); f = SD.open("test.txt", true, false);