From f4258152cf378d8f17f8d204be3a70fabcb05e99 Mon Sep 17 00:00:00 2001 From: FakuFaku Date: Thu, 8 Nov 2012 09:12:10 +0100 Subject: [PATCH] In SD.init, when already open, close root directory before trying to init. --- libraries/SD/SD.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libraries/SD/SD.cpp b/libraries/SD/SD.cpp index c746809b6ec..9a966e8466d 100644 --- a/libraries/SD/SD.cpp +++ b/libraries/SD/SD.cpp @@ -340,6 +340,13 @@ boolean SDClass::begin(uint8_t csPin) { Return true if initialization succeeds, false otherwise. */ + + /* before trying to initialize the card, close the root if open */ + /* this fixes a bug when we turn off the SD card to save power */ + if (root.isOpen()) + if (!root.close()) + return false; + return card.init(SPI_HALF_SPEED, csPin) && volume.init(card) && root.openRoot(volume);