Cannot get SD card to work

Posted on
  • Hi folks,

    I had wired up an SD card socket from Sparkfun:

    https://www.mouser.com/ProductDetail/Spa­rkFun-Electronics/DEV-13743/?qs=WyAARYrb­Sna7AKzdOk0X8g%3D%3D&gclid=Cj0KCQiAsqLSB­RCmARIsAL4Pa9TQXhYrFu8L0QQcDVMAQE91NwG4R­Am4irzcp8LHGGQq_icz7bBiY6saAuxPEALw_wcB

    But I keep getting the message, even with multiple different SD cards, all formatted to Fat32.

    "Uncaught Error: Unable to mount media : NOT_READY
        at line 6 col 41
         console.log(require("fs").readdirSync())­;"
    

    I triple-checked all the connections, and then used a meter to check connectivity, power, shorts, etc. They were all correct.

    So I figured it must be the socket. I removed it and soldered this one on in it's place, figuring that perhaps the added voltage regulation circuit might help:

    https://www.adafruit.com/product/254?gcl­id=Cj0KCQiAsqLSBRCmARIsAL4Pa9SFqtMV7P6ij­T3YC_O2wkmDjScGyUWDSlxgrcYFvsitDs03yyHVn­2oaApQ7EALw_wcB

    But I still get the exact same error message. Am I missing something obvious here? Again, I checked all the connections and they're fine. I have a DS18B20 connected to different pins and it works great, so the Espruino appears to be fine. Test program for SD card looks like this:

    
    function onInit() {
      console.log("Connected!");
      // Wire up up MOSI, MISO, SCK and CS pins (along with 3.3v and GND)
      SPI1.setup({mosi:B5, miso:B4, sck:B3});
      E.connectSDCard(SPI1, B6 /*CS*/);
      // see what's on the device
      console.log(require("fs").readdirSync())­;  
      for (var i in files)
        console.log("Found file "+files[i]);
    
      var f = E.openFile("log.txt", "w");
      f.write("Testing 123");
      f.close();
      
      f = E.openFile("log.txt", "r");
      f.pipe(console.log);
      f.close();
    }
    
    
  • That all looks fine to me - SD cards should be 3.3v, as is the Espruino - so you shouldn't need level conversion circuitry.

    However you are doing this in onInit - what if you just paste the commands into the left-hand side one by one to test?

    I have found that sometimes the SD cards take a few seconds to start working after they're powered on - I'm not sure if that could be an issue here...

  • I actually did exactly as you suggest, cutting and pasting from the code above. I'm really at a loss as to how to debug, as I've had no issues getting these adapters to work with Arduinos, Rasp PIs, etc.

  • Have you tried different SD cards, and cards that you're sure are FAT32 formatted?

    I actually just tried this with a Pico and it works fine - however I have a 2GB card that it doesn't appear to work with, but I'm also having trouble with the Espruino WiFi.

    I'll try and track this down a bit more as it should really be more resilient, but it might be a few weeks as I'm waiting for a micro SD card breakout.

  • Yes, tried with a number of cards and both sockets. Cards were formatted Fat32 on a Linux machine with parted. They could be read by a Windows machine as well.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Cannot get SD card to work

Posted by Avatar for user84292 @user84292

Actions