File tree 2 files changed +11
-3
lines changed
2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -250,6 +250,7 @@ uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
250
250
// 16-bit init start time allows over a minute
251
251
unsigned int t0 = millis ();
252
252
uint32_t arg;
253
+ bool useCmd1 = false ;
253
254
254
255
// set pin modes
255
256
pinMode (chipSelectPin_, OUTPUT);
@@ -309,13 +310,18 @@ uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
309
310
// initialize card and send host supports SDHC if SD2
310
311
arg = type () == SD_CARD_TYPE_SD2 ? 0X40000000 : 0 ;
311
312
312
- while ((status_ = cardAcmd (ACMD41, arg)) != R1_READY_STATE) {
313
+ status_ = cardAcmd (ACMD41, arg);
314
+ while (status_ != R1_READY_STATE) {
313
315
// check for timeout
314
- unsigned int d = millis () - t0;
315
- if (d > SD_INIT_TIMEOUT) {
316
+ if (((uint16_t )millis () - t0) > SD_INIT_TIMEOUT) {
316
317
error (SD_CARD_ERROR_ACMD41);
317
318
goto fail;
318
319
}
320
+ // Switch to CMD1 if the card fails to recognize ACMD41
321
+ if (status_ & R1_ILLEGAL_COMMAND) {
322
+ useCmd1 = true ;
323
+ }
324
+ status_ = (!useCmd1 ? cardAcmd (ACMD41, arg) : cardCommand (CMD1, 0 ));
319
325
}
320
326
// if SD2 read OCR register to check for SDHC card
321
327
if (type () == SD_CARD_TYPE_SD2) {
Original file line number Diff line number Diff line change 34
34
// SD card commands
35
35
/** GO_IDLE_STATE - init card in spi mode if CS low */
36
36
uint8_t const CMD0 = 0X00 ;
37
+ /** SEND_OP_COND - Initiate initialization process (used for MMC card) */
38
+ uint8_t const CMD1 = 0x01 ;
37
39
/** SEND_IF_COND - verify SD Memory Card interface operating condition.*/
38
40
uint8_t const CMD8 = 0X08 ;
39
41
/** SEND_CSD - read the Card Specific Data (CSD register) */
You can’t perform that action at this time.
0 commit comments