Skip to content

Commit 6cbb866

Browse files
committed
Adding CS pin parameter to SD.begin(). Defaults to 4 (for Arduino Ethernet Shield).
http://code.google.com/p/arduino/issues/detail?id=400
1 parent 8629da8 commit 6cbb866

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

libraries/SD/SD.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@
5252

5353
#include "SD.h"
5454

55-
// Use this to configure the chip select pin of the SD card.
56-
#define SD_CARD_CHIP_SELECT_PIN 4 // For use with Arduino Ethernet Shield
57-
58-
5955
// Used by `getNextPathComponent`
6056
#define MAX_COMPONENT_LEN 12 // What is max length?
6157
#define PATH_COMPONENT_BUFFER_LEN MAX_COMPONENT_LEN+1
@@ -311,7 +307,9 @@ boolean callback_openPath(SdFile& parentDir, char *filePathComponent,
311307

312308
/* Implementation of class used to create `SDCard` object. */
313309

314-
void SDClass::begin() {
310+
311+
312+
void SDClass::begin(uint8_t csPin) {
315313
/*
316314
317315
Performs the initialisation required by the sdfatlib library.
@@ -320,7 +318,7 @@ void SDClass::begin() {
320318
321319
*/
322320
// TODO: Allow chip select pin to be supplied?
323-
if (!(card.init(SPI_HALF_SPEED, SD_CARD_CHIP_SELECT_PIN)
321+
if (!(card.init(SPI_HALF_SPEED, csPin)
324322
&& volume.init(card) && root.openRoot(volume))) {
325323
while (true) {
326324
// Bail

libraries/SD/SD.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
3-
MemoryCard - a slightly more friendly wrapper for sdfatlib
3+
SD - a slightly more friendly wrapper for sdfatlib
44
55
This library aims to expose a subset of SD card functionality
66
in the form of a higher level "wrapper" object.
@@ -20,6 +20,9 @@
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+
2326
class SDClass {
2427

2528
private:
@@ -32,7 +35,7 @@ class SDClass {
3235
public:
3336
// This needs to be called to set up the connection to the memory card
3437
// before other methods are used.
35-
void begin();
38+
void begin(uint8_t csPin = SD_CARD_CHIP_SELECT_PIN);
3639

3740
// Open the specified file/directory with the supplied mode (e.g. read or
3841
// write, etc). Once opened the file can be accessed via the

0 commit comments

Comments
 (0)