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:
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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.
|
||||||
|
@ -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.");
|
||||||
|
@ -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);
|
||||||
|
Reference in New Issue
Block a user