Micro SD Card stopped working ?

18 Nov 2009

Hi all,..

I have a Micro SD card wired up to my mbed.

Description: Mbed Pin : MicroSD Pin :

Mosi  :  p5 : 3

Miso  : p6 : 7

CLK   : p7 : 5

CS     : p8 : 2

I've checked and double checked my wiring.

I've got the hello world SD card program.

#include "mbed.h"
#include "SDFileSystem.h"
SDFileSystem sd(p5, p6, p7, p8, "test"); //i, o, clk, cs, const : on the card 3,7,5,2
int main() {
    printf("Hello World!\n");  
    FILE *fp = fopen("/test/ttt.txt", "w");
    if(fp == NULL) {
        error("Could not open file for write\n");
    } else {
    fprintf(fp, "Hello SD Card World!");
    fclose(fp);
    printf("Goodbye World!\n");
    }
}

I've got TeraTerm so I can see whats happening.

and all I get is..

Hello World!
Not in idle state
Could not open file for write

I can write to the card with a PC, I've tried 2 different cards, I've tried 2 different mbeds, I've tried 3 different card holders (!! just in case) I've gone crazy with a multimeter to make sure everything is as it should be.

Can anyone verify that the SD Card libraries still work.

I'm half hoping something has broken them.. otherwise I've gone mad !

cheers

Dave.

 

 

18 Nov 2009 . Edited: 18 Nov 2009

Can you check if you can read the files?

Edit: actually, I could find the mysterious string in the source:

int SDFileSystem::disk_initialize() {
	    _spi.frequency(100000); // Set to 100kHz for initialisation
	    
	    // Initialise the card by clocking it a bit (cs = 1)
	    for(int i=0; i<16; i++) {   
	        _spi.write(0xFF);
	    }
	    // send CMD0, should return with all zeros except IDLE STATE set (bit 0)
	    if(_cmd(0, 0) != 0x01) { 
	        fprintf(stderr, "Not in idle state\n");
	        return 1;
	    }

So it seems the card initialization doesn't work...

18 Nov 2009

Hi Dave,

Can you confirm this stopped working, or whether you've just never got it working?

If it the later, I suspect it is just that the type of card you are using is not supported. The description of this peripheral is at:

and you'll notice I only ever had 2 different 1GB cards to hand. In particular, at the time I obviously suggested that it was unlikely to work with other (especially bigger) cards.

The reason is that the SD Card spec has lots of different paths depending on revision of protocol and size of the card. I only implemented some of this as I couldn't test anything else. It'd be good to expand this support at some point, so maybe we can diagnose some things...

If it is the first option, and it has stopped working, i'm not sure what to suggest. What card are you using?

Simon

19 Nov 2009

Its a SanDisk 1GB card. (I didn't go bigger on purpose!).

Its plain old MicroSD, rather than SDHC  or anything strange.

and I just have a MicroSD Card holder from Farnell connected to those pins on the mbed.

(I've double checked them six times, checked pin outs etc etc)

Here's the rub.. I'm 92% sure I had it working.., (but not with these cards) the problem is I did all my SD card stuff about a month ago..  was happy with it,.. wandered off to do other stuff, have gone back to implementing the SD Card stuff, and its not working ! (there were new revisions of the mbed and fat system libraries to bring in, and i wondered if the recent upgrades have broken something somewhere ? )

annoyingly the card I had is now in someone else's camera (its a long story).. so these are new cards)

I have an SDBreakOut board here too.. that I have definitely 100% had working.

So I shall get that connected up on a breadboard later, and double check that works still.

I admit I'm not totally au fait with the insides of the OS, (thats the point isn't it !) so I didnt know if any of the recent upgrades could have broke it.

I was hoping someone could connect a MicroSDCard up to those SPI pins and confirm it still works.

 

 

 

19 Nov 2009 . Edited: 19 Nov 2009

Hi David,

I've just been testing on a 1GB Kingston and 1GB Transcend card, but will aim to test on different cards over time.

 

I've just copied it form the SDCard Cookbook page. Unfortunately I know for sure that the only cards I've found which are working with the current SDFileSystem is a Kingston and a Transcend card.

I have a SanDisk TransFlash 256 MByte Card here which is not working as well as a 2GByte Kingston. At the moment I can say for sure that ...

Kingston 1 GByte MircroSD

Transcend 1 GByte MircroSD

... are working, if anyone has other Cards it would be good to know if they are working or not. (Maybe just post here)

Well, sadly I think you've made a bad swap your new Card is not working at the moment.

Rolf

19 Nov 2009

dang it..

many thanks for checking that for me.

I'll get another card, test that, and then I'll be able to def confirm if its these SanDisk cards that are the problem.

I'll post the results when I have 'em. Cheers.

 

19 Nov 2009

Hi David,

I've just done some tests with some different disks, and here is some interesting diagnosis information based on your initial error message report:

All the cards we have that don't work will fail with the error "Timeout waiting for card", as it tries to sends a certain initialisation command to the card.

However, you reported it was giving you the error "Not in idle state", which is concerned with making a connection and the disk being in an idle state. This failure is consistent with the card not being connected properly (but may well be other things).

Can you retest and confirm which error you are getting. If it is "Not in idle state", i'd have one last look at your SPI, Chip Select and power connections, and ensure they line up with the SD card and the pins in your code. Please report on what you find.

Simon

19 Nov 2009

 

ah.. yes..

do you know it was doing "timeout waiting for card" as well as "Not in Idle State."

It was intermittently doing either

I thought the not in idle state one was going to be the important one, and the time out waiting for card the "I need wiggling" one.

I now have a Kingston and a Transend card winging their way towards me, I'll do some testing with them when they get here. (probably going to be Monday now)

(I'm pretty sure the one thats currently in Sri Lanka in a Camera is a Transcend.. grrr)

I popped out at lunchtime, but could only source SanDisk ones from my local shop. Which was annoying.

takes me 5 mins to connect up.. so I'll give it another go in my tea break.. you'd think that one microSD card would be the same as another microSD card wouldn't you.

sorry for the staccato post.. I'm trying to do 3 things at once !

cheers

Dave.

 

19 Nov 2009

Here's a good one..

5 reboots of Mbed and then I got..

This disk tastes funny! I only like 512-byte blocks which is a new one.

and with the disk not in..

I either get..

Initialising
Didn't get a response from the disk
Set block timeout

or

The "not in idle state " message.

I'm not getting the timeout message at all.

I shall discard the board I have fitted up with the holder as "duff" and concentrate on the other two.

(I have 3 boards fitted up with holders)

 

20 Nov 2009 . Edited: 20 Nov 2009

In the words of Frankenstein.

ITS ALIVE...

A Kingston card works just fine,.. A Transcend card works just fine..

a SanDisk one doesn't.

and they all say they are normal micro SD Cards.

well.. at least I know it wasn't me going mad !

thanks for your help everyone.

 

22 Mar 2010

I don't know if this is still an active problem, but I compiled the code in the cookbook and got the no-go message.  Based on some experiments my son had been doing with SD drivers, I just cut and pasted the _com(0, 0); command from the code snippet  given above and put it in front of the if(...  so that it tried twice.

// send CMD0, should return with all zeros except IDLE STATE set (bit 0)
_cmd(0, 0)

	    if(_cmd(0, 0) != 0x01) { 
	        fprintf(stderr, "Not in idle state\n");
	        return 1;

 

 

Worked a treat......new San Disk 2Gb 15MB/sec card also change 100000 speed to 400000 as that is ? standard?

 

I don't know why it works, but it worked with an old SDccard and some other software that wasn't responding too.

 

Tim

 

 

22 Mar 2010

I don't know if this is still an active problem, but I compiled the code in the cookbook and got the no-go message.  Based on some experiments my son had been doing with SD drivers, I just cut and pasted the _com(0, 0); command from the code snippet  given above and put it in front of the if(...  so that it tried twice.

// send CMD0, should return with all zeros except IDLE STATE set (bit 0)
           _cmd(0, 0)
	    if(_cmd(0, 0) != 0x01) { 
	        fprintf(stderr, "Not in idle state\n");
	        return 1;

 

 

Worked a treat......new San Disk 2Gb 15MB/sec card also change 100000 speed to 400000 as that is ? standard?

 

I don't know why it works, but it worked with an old SDccard and some other software that wasn't responding too.

 

Tim

 

 

22 Mar 2010

I've done some more experiments since then and got some code supporting all the old and new cards I had at my disposal. Still very experimental code, but may well be useful:

SDCards!

Simon