1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Using sdfatlib CS pin defaults. SD.begin() returns success or failure.

This commit is contained in:
David A. Mellis
2010-11-20 13:50:45 -05:00
parent 6f0ea10600
commit d05a57af19
4 changed files with 16 additions and 15 deletions

View File

@ -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. 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? return card.init(SPI_HALF_SPEED, csPin) &&
if (!(card.init(SPI_HALF_SPEED, csPin) volume.init(card) &&
&& volume.init(card) && root.openRoot(volume))) { root.openRoot(volume);
while (true) {
// Bail
}
}
} }

View File

@ -20,9 +20,6 @@
#include <utility/SdFat.h> #include <utility/SdFat.h>
#include <utility/SdFatUtil.h> #include <utility/SdFatUtil.h>
// 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 { class File : public Stream {
public: public:
virtual void write(uint8_t); virtual void write(uint8_t);
@ -47,7 +44,7 @@ private:
public: public:
// This needs to be called to set up the connection to the SD card // This needs to be called to set up the connection to the SD card
// before other methods are used. // 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 // Open the specified file/directory with the supplied mode (e.g. read or
// write, etc). Returns a File object for interacting with the file. // write, etc). Returns a File object for interacting with the file.

View File

@ -6,7 +6,11 @@ void setup()
{ {
Serial.begin(9600); Serial.begin(9600);
Serial.print("Initializing SD card..."); 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."); Serial.println("done.");
if (SD.exists("example.txt")) Serial.println("example.txt exists."); if (SD.exists("example.txt")) Serial.println("example.txt exists.");

View File

@ -6,7 +6,11 @@ void setup()
{ {
Serial.begin(9600); Serial.begin(9600);
Serial.print("Initializing SD card..."); 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."); Serial.println("done.");
f = SD.open("test.txt", true, false); f = SD.open("test.txt", true, false);