File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 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) {
250250 // 16-bit init start time allows over a minute
251251 unsigned int t0 = millis ();
252252 uint32_t arg;
253+ bool useCmd1 = false ;
253254
254255 // set pin modes
255256 pinMode (chipSelectPin_, OUTPUT);
@@ -309,13 +310,18 @@ uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
309310 // initialize card and send host supports SDHC if SD2
310311 arg = type () == SD_CARD_TYPE_SD2 ? 0X40000000 : 0 ;
311312
312- while ((status_ = cardAcmd (ACMD41, arg)) != R1_READY_STATE) {
313+ status_ = cardAcmd (ACMD41, arg);
314+ while (status_ != R1_READY_STATE) {
313315 // check for timeout
314- unsigned int d = millis () - t0;
315- if (d > SD_INIT_TIMEOUT) {
316+ if (((uint16_t )millis () - t0) > SD_INIT_TIMEOUT) {
316317 error (SD_CARD_ERROR_ACMD41);
317318 goto fail;
318319 }
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 ));
319325 }
320326 // if SD2 read OCR register to check for SDHC card
321327 if (type () == SD_CARD_TYPE_SD2) {
Original file line number Diff line number Diff line change 3434// SD card commands
3535/** GO_IDLE_STATE - init card in spi mode if CS low */
3636uint8_t const CMD0 = 0X00 ;
37+ /** SEND_OP_COND - Initiate initialization process (used for MMC card) */
38+ uint8_t const CMD1 = 0x01 ;
3739/** SEND_IF_COND - verify SD Memory Card interface operating condition.*/
3840uint8_t const CMD8 = 0X08 ;
3941/** SEND_CSD - read the Card Specific Data (CSD register) */
You can’t perform that action at this time.
0 commit comments