Fix SD Card not properly initializing

This commit is contained in:
me-no-dev 2017-07-07 11:34:54 +03:00
parent 9d0ae7a6be
commit 13bb22de30

View File

@ -84,22 +84,14 @@ void sdDeselectCard(uint8_t pdrv)
{ {
ardu_sdcard_t * card = s_cards[pdrv]; ardu_sdcard_t * card = s_cards[pdrv];
digitalWrite(card->ssPin, HIGH); digitalWrite(card->ssPin, HIGH);
card->spi->write(0xFF);
} }
bool sdSelectCard(uint8_t pdrv) bool sdSelectCard(uint8_t pdrv)
{ {
ardu_sdcard_t * card = s_cards[pdrv]; ardu_sdcard_t * card = s_cards[pdrv];
digitalWrite(card->ssPin, LOW); digitalWrite(card->ssPin, LOW);
card->spi->write(0xFF); sdWait(pdrv, 300);
if (sdWait(pdrv, 500)) {
return true; return true;
} else {
log_e("timeout");
sdDeselectCard(pdrv);
return false;
}
} }
char sdCommand(uint8_t pdrv, char cmd, unsigned int arg, unsigned int* resp) char sdCommand(uint8_t pdrv, char cmd, unsigned int arg, unsigned int* resp)
@ -448,6 +440,11 @@ DSTATUS ff_sd_initialize(uint8_t pdrv)
card->spi->beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE0)); card->spi->beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE0));
digitalWrite(card->ssPin, HIGH);
for (uint8_t i = 0; i < 20; i++) {
card->spi->transfer(0XFF);
}
if (sdTransaction(pdrv, GO_IDLE_STATE, 0, NULL) != 1) { if (sdTransaction(pdrv, GO_IDLE_STATE, 0, NULL) != 1) {
log_w("GO_IDLE_STATE failed"); log_w("GO_IDLE_STATE failed");
goto unknown_card; goto unknown_card;