Skip to content

Crash when using SD library and no card is present #1815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bHogan2 opened this issue Mar 25, 2016 · 3 comments
Closed

Crash when using SD library and no card is present #1815

bHogan2 opened this issue Mar 25, 2016 · 3 comments

Comments

@bHogan2
Copy link

bHogan2 commented Mar 25, 2016

WDT error under circumstances described below.

Hardware

Hardware: ESP-12
Core Version: 2.1.0 stable
OS: Win10

Description

I'm using an I2C OLED and an SPI SD card. Under 2.0.0 I could run both together - as long as I started SPI before I2C. (A workaround) If I didn't, I could still read the card, but if there was NO CARD, the ESP would hang with a WDT error.

With 2.1.0 it doesn't matter which I do first, I'll always get the WDT hang.
Not sure why - but wanted to call the difference to your attention in case it rings a bell..

Settings in IDE

Module: Generic ESP8266 Module
Flash Size: 512k
CPU Frequency: 80Mhz
Flash Mode: DIO
Flash Frequency: 80Mhz
Upload Using: SERIAL
Reset Method: ck

Sketch

pseudocode of a big sketch . . .

void setup() {
EEPROM.begin(4096); // FWIW
SPI.begin()

if (! SD.begin(SD_SELECT)) { // triggers the WDT error if no card
Serial.println("No Card");
return NO_CARD;
}
SPI.end(); //done with SPI so close it so pins can be reused
///////////////////////////////////
Wire.pins(SDA_PIN, SCL_PIN); // define pins used for I2C
Wire.begin(); // HAD TO DO THIS AFTER SPI else "no card WDT reset"
}

void loop() {
}

#define SDA_PIN         0               // I2C SDA pin (pulled up) + PGM button and LED
#define SCL_PIN         2               // I2C SCL pin (pulled up)
#define MISO_PIN     12               // (when used) MISO (DO on SD)   
#define MOSI_PIN      13              // MOSI (DI on SD)
#define SCLK_PIN      14               // SCLK (SCK on SD)
#define CS_PIN           15              // SS (CS on SD)- always LOW that's OK - not used
// WAKE                16               // wired to RESET through cap to wake from sleep

### Debug Messages

WDT timeout






<bountysource-plugin>

---
Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/32238017-crash-when-using-sd-library-and-no-card-is-present?utm_campaign=plugin&utm_content=tracker%2F14245935&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F14245935&utm_medium=issues&utm_source=github).
</bountysource-plugin>
@bHogan2 bHogan2 changed the title With v2.2.0 core, can no longer run SPI and I2C together With v2.1.0 core, can no longer run SPI and I2C together Mar 25, 2016
@pipi61
Copy link

pipi61 commented Mar 25, 2016

Hi!
Try in c:\Arduino167\hardware\esp8266com\esp8266\libraries\SD\src\utility\Sd2Card.cpp
in Sd2Card::init function:
.....
while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {
if (((uint16_t)(millis() - t0)) > SD_INIT_TIMEOUT) {
error(SD_CARD_ERROR_CMD0);
goto fail;
}
}
.....
change to:
while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE)

{
if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
error(SD_CARD_ERROR_CMD0);
goto fail;
}
yield();
}

@bHogan2
Copy link
Author

bHogan2 commented Mar 25, 2016

Thank you. Appreciated. Makes sense. Made change but 2.0.0 still needs SPI init before I2C init (for some reason).
Haven't tried going back to 2.1.0.
In any case, you mod should probable be included in the next lib - IMHO.

@igrr igrr changed the title With v2.1.0 core, can no longer run SPI and I2C together Crash when using SD library and no card is present Mar 27, 2016
@igrr igrr added this to the 2.2.0 milestone Mar 27, 2016
@igrr igrr modified the milestones: 2.2.0, 2.3.0 Apr 18, 2016
igrr added a commit that referenced this issue Jun 13, 2016
@igrr
Copy link
Member

igrr commented Jun 13, 2016

Fixed in 9172033

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants