SD storage format issue

Dear All,
Spent entire day on figuring out what wrong with SD card slot :’(. Given below is the code I am using (cut and paste from GHI reference manual). Every time it says unrecognized file format. I have formatted(FAT32) it many time on my XP machine using my card reader/writer but no use.

Is there any bug in the APIs?

When I plug the same card in my card reader and plug that into USBHost slot of FEZ Rhino. I am able to detect a storage device and able to read the same card and files on it.

Could there be SD card slot issue? I am using Transcent 2GB microSD card.

This capability is important for me for logging data. Please let me know your views on this.


public class Program
{
// Hold a static reference in case the GC kicks in and disposes it automatically, note that we only support one in this example!
static PersistentStorage ps;

    public static void Main()
    {
        // Subscribe to RemovableMedia events
        RemovableMedia.Insert += RemovableMedia_Insert;
        RemovableMedia.Eject += RemovableMedia_Eject;

        // Assume SD card is inserted
        // Create a new storage device
        ps = new PersistentStorage("SD");
        ps.MountFileSystem();

        // Sleep forever
        Thread.Sleep(Timeout.Infinite);
    }

    static void RemovableMedia_Insert(object sender, MediaEventArgs e)
    {
        Debug.Print("Storage \"" + e.Volume.RootDirectory + "\" is inserted.");
        Debug.Print("Getting files and folders:");
        if (e.Volume.IsFormatted)
        {
            string[] files = Directory.GetFiles(e.Volume.RootDirectory);
            string[] folders = Directory.GetDirectories(e.Volume.RootDirectory);

            Debug.Print("Files available on " + e.Volume.RootDirectory + ":");
            for (int i = 0; i < files.Length; i++)
                Debug.Print(files[i]);

            Debug.Print("Folders available on " + e.Volume.RootDirectory + ":");
            for (int i = 0; i < folders.Length; i++)
                Debug.Print(folders[i]);
        }
        else
        {
            Debug.Print("Storage is not formatted. Format on PC with FAT32/FAT16 first.");
        }

        // We do not need it any more
        ps.Dispose();
    }

    static void RemovableMedia_Eject(object sender, MediaEventArgs e)
    {
        Debug.Print("Storage \"" + e.Volume.RootDirectory + "\" is ejected.");
    }



}

}


You are talking about SD cards but the example is for USB! Am I over looking something?

see this please microframeworkprojects.com

Modified the code In orignal post. Sorry for the wrong code posted earlier.
Please check the code now. I get the insert event and i tried to read the card. This is as per GHI SDK.

In all variants of code, this line fails. I have checked the volumeInfo object and find infomation about filesystem etc. missing.

if (VolumeInfo.GetVolumes()[0].IsFormatted)

In case I do not check I get the IO expection “Unsupported Filesystem”. I can read the same card on my XP machine and also using FEz Rihno USHHost interface, when I plug the cardreader with SD card inside.

Did you try FAT and FAT32?
Dud you try format without using “quick format” option? I mean use full format.
What size is your card?
What brand is your card?

[quote]Could there be SD card slot issue? I am using Transcent 2GB microSD card.
[/quote]

oeps, didn’t noticed Wouter’s reply ::slight_smile:

Did you try FAT and FAT32?

zkumar: I have used FAT32

Dud you try format without using “quick format” option? I mean use full format.

Zumar: I did full Format

What size is your card?
Zkumar: 2GB

What brand is your card?

Transcent

what is support policy if ther is hardware issue?

There is no hardware issues and all cards of any size should work fine. If you have a card that doesn’t work, you can either point us out to where we can get eh same card online so we can try it or mail us your card, we will test and send it back to you with a gift :slight_smile:

Try to format using FAT instead of FAT32. Have you tried a different card?

[quote] Every time it says unrecognized file format. I have formatted(FAT32) it many time on my XP machine using my card reader/writer but no use.
[/quote]
So sometimes it works and sometimes it doesn’t?

Try connecting a power pack.

Tried another card with FAT32 same problem. I am not how can we say ther is no hardware problem?

Where are you located? Can you mail us your card and your board back? We will test and let you know the results

You didn’t answer my question…

Dear Mike,
thanks for your help. Your trick worked. I have powered it externally and I could read the card now. You guys so nice. Thanks for bearing with me. I am very happy with my FEZ and really excited about it. Next thing I have to put wiznet and zigbee to this.

I am going to have a peaceful sleep tonight.

Hi,

I just test out the SD capability of the Rhino board and using the same code provided by GHI which is the same as zkumar, i get an exception at the line

ps = new PersistentStorage(“SD”);

Even with the power pack plug in.

SD card is 4G Corsair

Thanks,

It shouldn’t. Can you try another card?

/

Ok I’ll buy another card and try again and let you know.

When I use the class method to detect the SD card it works when i inserting and removing, correct me if I am wrong I guess this method only look for the an interrupt pin connected to the SD card when it is inserting or removing?

//Detect for SD card
if (PersistentStorage.DetectSDCard())
{
Debug.Print(“SD card is inserted.”);
}
else
{
Debug.Print(“No SD card detected”);
}

Please use code tags so it is easy to read code.

like this…

//Detect for SD card 
if (PersistentStorage.DetectSDCard())
{
Debug.Print("SD card is inserted."); 
}
else
{
Debug.Print("No SD card detected");
}

Well, I bought 2 more micro SD, this time to be safe they are 4G Kingston and PNY 2G.

  1. Both formatted (not quick format) as FAT, still threw the same exception.

  2. Both formatted (not quick format) as FAT32, still threw the same
    exception.

so far, USB mass storage works with my 4G and 8G, micro SD no luck.

Thanks,