From 8704331b3a8ca874499cd190638970c4fda3aafe Mon Sep 17 00:00:00 2001 From: mohamadkhani Date: Tue, 26 Sep 2017 18:03:25 +0330 Subject: [PATCH 1/4] Add Ability to close spi SD card connection --- libraries/SD/src/utility/Sd2Card.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libraries/SD/src/utility/Sd2Card.cpp b/libraries/SD/src/utility/Sd2Card.cpp index 553bb9ba2a..5ceb530eca 100644 --- a/libraries/SD/src/utility/Sd2Card.cpp +++ b/libraries/SD/src/utility/Sd2Card.cpp @@ -350,6 +350,13 @@ uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) { return false; } //------------------------------------------------------------------------------ +/** + * End SPI Connection + */ +void Sd2Card::end(){ + SPI.end(); +} +//------------------------------------------------------------------------------ /** * Enable or disable partial block reads. * From e2ac34d7b3af2922fd4ceb1ee99b6b88fc0b3c7f Mon Sep 17 00:00:00 2001 From: mohamadkhani Date: Tue, 26 Sep 2017 18:04:49 +0330 Subject: [PATCH 2/4] Add Ability to close spi SD card connection --- libraries/SD/src/utility/Sd2Card.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/SD/src/utility/Sd2Card.h b/libraries/SD/src/utility/Sd2Card.h index c7e54f66b2..3c229f6b3b 100644 --- a/libraries/SD/src/utility/Sd2Card.h +++ b/libraries/SD/src/utility/Sd2Card.h @@ -200,6 +200,10 @@ class Sd2Card { } uint8_t init(uint8_t sckRateID, uint8_t chipSelectPin); #endif + /** + * End SPI Connection + */ + void end(); void partialBlockRead(uint8_t value); /** Returns the current value, true or false, for partial block read. */ uint8_t partialBlockRead(void) const {return partialBlockRead_;} From 3129ef1688f0dd33841fb1078c4b82f64041e903 Mon Sep 17 00:00:00 2001 From: mohamadkhani Date: Tue, 26 Sep 2017 18:06:08 +0330 Subject: [PATCH 3/4] Add Ability to close SD card connection --- libraries/SD/src/SD.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/SD/src/SD.h b/libraries/SD/src/SD.h index 38ad793598..9d76299c20 100644 --- a/libraries/SD/src/SD.h +++ b/libraries/SD/src/SD.h @@ -88,7 +88,11 @@ class SDClass { // This needs to be called to set up the connection to the SD card // before other methods are used. boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN, uint32_t speed = SPI_HALF_SPEED); - + + //Performs end The SD Card and close the spi connection + //and to able begin SD Card again without error + void end(); + // Open the specified file/directory with the supplied mode (e.g. read or // write, etc). Returns a File object for interacting with the file. // Note that currently only one file can be open at a time. From a132f39ca58920b15f7845e2713c684408f22f22 Mon Sep 17 00:00:00 2001 From: mohamadkhani Date: Tue, 26 Sep 2017 18:08:24 +0330 Subject: [PATCH 4/4] Update SD.cpp --- libraries/SD/src/SD.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libraries/SD/src/SD.cpp b/libraries/SD/src/SD.cpp index 9748130373..e4a2e78977 100644 --- a/libraries/SD/src/SD.cpp +++ b/libraries/SD/src/SD.cpp @@ -345,6 +345,18 @@ boolean SDClass::begin(uint8_t csPin, uint32_t speed) { root.openRoot(volume); } + +void SDClass::end() { + /* + + Performs to end The SD Card and close the spi connection + and to able begin SD Card again without error + + */ + root.close(); + card.end(); +} + // this little helper is used to traverse paths SdFile SDClass::getParentDir(const char *filepath, int *index) { // get parent directory