Skip to content

Commit

Permalink
Improved card re-initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
greiman committed Jan 4, 2019
1 parent 37c1f26 commit 60864e3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SdFat
version=1.0.13
version=1.0.14
author=Bill Greiman <[email protected]>
maintainer=Bill Greiman <[email protected]>
sentence=FAT16/FAT32 file system for SD cards.
Expand Down
5 changes: 2 additions & 3 deletions src/SdCard/SdInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ 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 */
/** CMD0 retry count */
const uint8_t SD_CMD0_RETRY = 10;
/** command timeout ms */
const uint16_t SD_CMD_TIMEOUT = 300;
/** init timeout ms */
Expand Down
14 changes: 11 additions & 3 deletions src/SdCard/SdSpiCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,17 @@ bool SdSpiCard::begin(SdSpiDriver* spi, uint8_t csPin, SPISettings settings) {
spiSelect();

// command to go idle in SPI mode
if (cardCommand(CMD0, 0) != R1_IDLE_STATE) {
error(SD_CARD_ERROR_CMD0);
goto fail;
for (uint8_t i = 0; cardCommand(CMD0, 0) != R1_IDLE_STATE; i++) {
if (i == SD_CMD0_RETRY) {
error(SD_CARD_ERROR_CMD0);
goto fail;
}
// stop multi-block write
spiSend(STOP_TRAN_TOKEN);
// finish block transfer
for (int i = 0; i < 520; i++) {
spiReceive();
}
}
#if USE_SD_CRC
if (cardCommand(CMD59, 1) != R1_IDLE_STATE) {
Expand Down
2 changes: 1 addition & 1 deletion src/SdFat.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#endif // INCLUDE_SDIOS
//------------------------------------------------------------------------------
/** SdFat version */
#define SD_FAT_VERSION "1.0.13"
#define SD_FAT_VERSION "1.0.14"
//==============================================================================
/**
* \class SdBaseFile
Expand Down

0 comments on commit 60864e3

Please sign in to comment.