Browse Source

Fix iinitialization for older cards

Bill Greiman 6 years ago
parent
commit
356c5e417c
5 changed files with 18 additions and 7 deletions
  1. 1 1
      library.properties
  2. 5 0
      src/SdCard/SdInfo.h
  3. 2 1
      src/SdCard/SdSpiCard.cpp
  4. 1 1
      src/SdFat.h
  5. 9 4
      src/SysCall.h

+ 1 - 1
library.properties

@@ -1,5 +1,5 @@
 name=SdFat
-version=1.0.11
+version=1.0.12
 author=Bill Greiman <fat16lib@sbcglobal.net>
 maintainer=Bill Greiman <fat16lib@sbcglobal.net>
 sentence=FAT16/FAT32 file system for SD cards.

+ 5 - 0
src/SdCard/SdInfo.h

@@ -120,6 +120,11 @@ const uint8_t SD_CARD_TYPE_SDHC = 3;
 #define SPI_SIXTEENTH_SPEED SD_SCK_HZ(F_CPU/32)
 //------------------------------------------------------------------------------
 // SD operation timeouts
+/** CMD0 loop delay ms */
+const uint16_t SD_CMD0_DELAY = 100;
+/** init timeout ms */
+/** command timeout ms */
+const uint16_t SD_CMD_TIMEOUT = 300;
 /** init timeout ms */
 const uint16_t SD_INIT_TIMEOUT = 2000;
 /** erase timeout ms */

+ 2 - 1
src/SdCard/SdSpiCard.cpp

@@ -143,6 +143,7 @@ bool SdSpiCard::begin(SdSpiDriver* spi, uint8_t csPin, SPISettings settings) {
       error(SD_CARD_ERROR_CMD0);
       goto fail;
     }
+    delayMS(SD_CMD0_DELAY);
   }
 #if USE_SD_CRC
   if (cardCommand(CMD59, 1) != R1_IDLE_STATE) {
@@ -208,7 +209,7 @@ uint8_t SdSpiCard::cardCommand(uint8_t cmd, uint32_t arg) {
     spiStart();
   }
   // wait if busy
-  waitNotBusy(SD_WRITE_TIMEOUT);
+  waitNotBusy(SD_CMD_TIMEOUT);
 
 #if USE_SD_CRC
   // form message

+ 1 - 1
src/SdFat.h

@@ -37,7 +37,7 @@
 #endif  // INCLUDE_SDIOS
 //------------------------------------------------------------------------------
 /** SdFat version */
-#define SD_FAT_VERSION "1.0.11"
+#define SD_FAT_VERSION "1.0.12"
 //==============================================================================
 /**
  * \class SdBaseFile

+ 9 - 4
src/SysCall.h

@@ -36,22 +36,27 @@
 #else  // defined(ARDUINO)
 #error "Unknown system"
 #endif  // defined(ARDUINO)
-//-----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 #ifdef ESP8266
 // undefine F macro if ESP8266.
 #undef F
 #endif  // ESP8266
-//-----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 #ifndef F
 /** Define macro for strings stored in flash. */
 #define F(str) (str)
 #endif  // F
-//-----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 /** \return the time in milliseconds. */
 inline uint16_t curTimeMS() {
   return millis();
 }
-//-----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+/** Delay milliseconds */
+inline void delayMS(uint16_t ms) {
+  delay(ms);
+}
+//------------------------------------------------------------------------------
 /**
  * \class SysCall
  * \brief SysCall - Class to wrap system calls.