Skip to content

Commit d05a57a

Browse files
committedNov 20, 2010
Using sdfatlib CS pin defaults. SD.begin() returns success or failure.
1 parent 6f0ea10 commit d05a57a

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed
 

‎libraries/SD/SD.cpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -319,21 +319,17 @@ boolean callback_remove(SdFile& parentDir, char *filePathComponent,
319319

320320

321321

322-
void SDClass::begin(uint8_t csPin) {
322+
boolean SDClass::begin(uint8_t csPin) {
323323
/*
324324
325325
Performs the initialisation required by the sdfatlib library.
326326
327-
Does not return if initialisation fails.
327+
Return true if initialization succeeds, false otherwise.
328328
329329
*/
330-
// TODO: Allow chip select pin to be supplied?
331-
if (!(card.init(SPI_HALF_SPEED, csPin)
332-
&& volume.init(card) && root.openRoot(volume))) {
333-
while (true) {
334-
// Bail
335-
}
336-
}
330+
return card.init(SPI_HALF_SPEED, csPin) &&
331+
volume.init(card) &&
332+
root.openRoot(volume);
337333
}
338334

339335

‎libraries/SD/SD.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
#include <utility/SdFat.h>
2121
#include <utility/SdFatUtil.h>
2222

23-
// Use this to configure the chip select pin of the SD card.
24-
#define SD_CARD_CHIP_SELECT_PIN 4 // For use with Arduino Ethernet Shield
25-
2623
class File : public Stream {
2724
public:
2825
virtual void write(uint8_t);
@@ -47,7 +44,7 @@ class SDClass {
4744
public:
4845
// This needs to be called to set up the connection to the SD card
4946
// before other methods are used.
50-
void begin(uint8_t csPin = SD_CARD_CHIP_SELECT_PIN);
47+
boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN);
5148

5249
// Open the specified file/directory with the supplied mode (e.g. read or
5350
// write, etc). Returns a File object for interacting with the file.

‎libraries/SD/examples/Files/Files.pde

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ void setup()
66
{
77
Serial.begin(9600);
88
Serial.print("Initializing SD card...");
9-
SD.begin();
9+
// On the Ethernet Shield, CS is pin 4.
10+
if (!SD.begin(4)) {
11+
Serial.println("failed!");
12+
return;
13+
}
1014
Serial.println("done.");
1115

1216
if (SD.exists("example.txt")) Serial.println("example.txt exists.");

‎libraries/SD/examples/ReadWrite/ReadWrite.pde

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ void setup()
66
{
77
Serial.begin(9600);
88
Serial.print("Initializing SD card...");
9-
SD.begin();
9+
// On the Ethernet Shield, CS is pin 4.
10+
if (!SD.begin(4)) {
11+
Serial.println("failed!");
12+
return;
13+
}
1014
Serial.println("done.");
1115

1216
f = SD.open("test.txt", true, false);

0 commit comments

Comments
 (0)
Please sign in to comment.