SD Card Initialization issue

Hi.
I’m pretty new in this NETMF world, but I have a lot of years of experience with electronics and programming: http://blog.tkjelectronics.dk

I tried hooking up an SD Card connector to my FEZ Panda as stated on this link: microframeworkprojects.com - This website is for sale! - microframeworkprojects Resources and Information.
Then I used the code from the “Beginners guide to NETMF”, and after adding a lot of references, it could be deployed successfully.
The references I added was:
[ulist]

After a couple of seconds after the Panda has been reset, the debugger throws me this exception:

I’ve tried searching the internet and on this forum for the error, and it looks like it has something to do with the initialization, and that the SD card can’t be initialized.

This is the C# code:

using System;
using System.IO;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.System;
using GHIElectronics.NETMF.IO;

namespace FEZ_Panda_Application1
{
    public class Program
    {
        public static void Main()
        {
            // ...
            // SD Card is inserted
            // Create a new storage device
            PersistentStorage sdPS = new PersistentStorage("SD");
            // Mount the file system
            sdPS.MountFileSystem();
            // Assume one storage device is available, access it through
            // Micro Framework and display available files and folders:
            Debug.Print("Getting files and folders:");
            if (VolumeInfo.GetVolumes()[0].IsFormatted)
            {
                string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
                string[] files = Directory.GetFiles(rootDirectory);
                string[] folders = Directory.GetDirectories(rootDirectory);

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

                Debug.Print("Folders available on " + 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.");
            }
            // Unmount
            sdPS.UnmountFileSystem();
        }

    }
}

I’ve also measured the SCLK with my Oscilloscope, and it is 300kHz.
Do you have any idea what is going on, as I’ve tried now with two different cards, and I have doubled checked the connections.

Best Regards
Thomas Jespersen

Step in code (using F10) and then you can see exactly what line is throwing the exception.

A similar problem had I when starting out with the SD card and it was solved by placing a short delay before the unmount. Apparently there is a "race "problem in the unmount coming too quickly after a mount. See this thread for additional info and comments [url]http://www.tinyclr.com/forum/2/159/#/2/[/url]

I wondered if these lines in bold below are actual on your code, as you posted previously??

using GHIElectronics.NETMF.IO;

FEZPanda_GHIElectronics.NETMF.FEZ
GHIElectronics.NETMF.Hardware
GHIElectronics.NETMF.IO
GHIElectronics.NETMF.System
Microsoft.SPOT.Hardware
Microsoft.SPOT.IO
Microsoft.SPOT.Native
mscorlib
System.IO

namespace FEZ_Panda_Application1
{

If so, you probably you need to comment out these lines.
These lines are references that you needed to add in the “References” in the “Solution Dialog”

To answer all your questions, I’ll start with you Gus.
Actually I had already ran thru the code with the debugger, I just forgot to post the line. The exception is thrown on this line:

PersistentStorage sdPS = new PersistentStorage("SD");

idafez: As the exception isn’t thrown in the end, I don’t think my problem has anything to do with yours…

Sam: The references listed are of course added to the reference list, while you will see those being used (using …) in the code posted. I have a couple of years of Visual Basic .NET and Visual C# .NET experience - so no problems there :slight_smile:

Best Regards
Thomas Jespersen

Your blog is exciting, looks like you are having a lot of fun :slight_smile:

Have you tried a different SD card?

Thank you… I’m trying to do projects with almost everything, but I don’t have the time :frowning: So currently I’ve set a FPGA project on hold to try the NETMF world.

About the SD cards; yes, I’ve tried with 3 different cards without any luck!

No ideas… Anybody?

Wiring is done correctly?
Soldering is good (continuity), no bridges or anything like that?

Wiring is done according to the SD Connection page.
And yes, the solder is correct - I’ve measured all the connections!

I was having difficulty with a panda and an SD card… Now I’ve the same program in my Panda II with a micro SD slot problems have gone… I’m putting it down to the SD-> micro adapter…

Cheers Ian

Any news on this. I have the same problem with a Panda and SD card. The SD card works perfect in my Cobra, but on the Panda it appears unformatted.
Any idea?

It is the exact same software that runs on panda and on cobra so it is probably something related to hardware.

Is this Panda or Panda II?

Panda

If wires are too long then maybe you need a decoupling capacitor on power pin of SD card, a 0.1uF capacitor.

Yes it’s the Panda (1).
The wires is short 8cm wires - so they are not that long!

Thomas

My wires are 2cm ( < 1" ). Is that considered long?

no but I would add it anyway as we do not know why it is not working… assuming you have double checked all your wiring.

Nope, it’s still not working. Neither with a 0.1uF (100nF) cap added!

I also have a problem with my Kingston 4GB SD HC card. I’m using Domino board however. I appended this topic with description of my problem:

[url]http://www.tinyclr.com/forum/18/1976/#/2/msg27434[/url]

I also receive an Exception in PersistentStorage constructor. What SD cards did you test ? I have no problems running Kingston 2GB SD card for example.