Publishing an updated SDFileSystem library

Dependencies:   FATFileSystem

Fork of SDFileSystem by Neil Thiessen

Revision:
25:923df4ee70c4
Parent:
24:a52e682a1ce4
diff -r a52e682a1ce4 -r 923df4ee70c4 SDFileSystem.cpp
--- a/SDFileSystem.cpp	Tue May 24 15:50:26 2016 +0000
+++ b/SDFileSystem.cpp	Thu May 26 15:32:31 2016 +0000
@@ -163,13 +163,23 @@
     //Set the SPI frequency to 400kHz for initialization
     m_Spi.frequency(400000);
 
-    //Send 80 dummy clocks with /CS deasserted and DI held high
-    m_Cs = 1;
-    for (int i = 0; i < 10; i++)
-        m_Spi.write(0xFF);
+    //Try to reset the card up to 3 times
+    for (int f = 0; f < 3; f++) {
+        //Send 80 dummy clocks with /CS deasserted and DI held high
+        m_Cs = 1;
+        for (int i = 0; i < 10; i++) {
+            m_Spi.write(0xFF);
+        }
 
-    //Send CMD0(0x00000000) to reset the card
-    if (commandTransaction(CMD0, 0x00000000) != 0x01) {
+        //Send CMD0(0x00000000) to reset the card
+        token = commandTransaction(CMD0, 0x00000000);
+        if (token == 0x01) {
+            break;
+        }
+    }
+
+    //Check if the card reset
+    if (token != 0x01) {
         //Initialization failed
         m_CardType = CARD_UNKNOWN;
         return m_Status;