mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Using sdfatlib CS pin defaults. SD.begin() returns success or failure.
This commit is contained in:
parent
6f0ea10600
commit
d05a57af19
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,9 +20,6 @@
|
||||
#include <utility/SdFat.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 {
|
||||
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.
|
||||
|
@ -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.");
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user