Skip to content

Commit

Permalink
Fix SD Card not properly initializing
Browse files Browse the repository at this point in the history
  • Loading branch information
me-no-dev committed Jul 7, 2017
1 parent 9d0ae7a commit 13bb22d
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions libraries/SD/src/sd_diskio.cpp
Expand Up @@ -84,22 +84,14 @@ void sdDeselectCard(uint8_t pdrv)
{
ardu_sdcard_t * card = s_cards[pdrv];
digitalWrite(card->ssPin, HIGH);
card->spi->write(0xFF);
}

bool sdSelectCard(uint8_t pdrv)
{
ardu_sdcard_t * card = s_cards[pdrv];
digitalWrite(card->ssPin, LOW);
card->spi->write(0xFF);

if (sdWait(pdrv, 500)) {
return true;
} else {
log_e("timeout");
sdDeselectCard(pdrv);
return false;
}
sdWait(pdrv, 300);
return true;
}

char sdCommand(uint8_t pdrv, char cmd, unsigned int arg, unsigned int* resp)
Expand Down Expand Up @@ -448,6 +440,11 @@ DSTATUS ff_sd_initialize(uint8_t pdrv)

card->spi->beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE0));

digitalWrite(card->ssPin, HIGH);

This comment has been minimized.

Copy link
@APokorny

APokorny Jul 11, 2017

Contributor

out of curiosity isnt that change required on every "transaction"?

This comment has been minimized.

Copy link
@APokorny

APokorny Jul 17, 2017

Contributor

Tried a few cards with this change included - seems to work fine her..

This comment has been minimized.

Copy link
@me-no-dev

me-no-dev Jul 17, 2017

Author Member

this is required in the beginning to put the card in proper SPI mode. It could maybe do with less zeroes sent, but 20 seemed like a safe spot.

for (uint8_t i = 0; i < 20; i++) {
card->spi->transfer(0XFF);
}

if (sdTransaction(pdrv, GO_IDLE_STATE, 0, NULL) != 1) {
log_w("GO_IDLE_STATE failed");
goto unknown_card;
Expand Down

0 comments on commit 13bb22d

Please sign in to comment.