Main Site Documentation

SD Card Initialization issue


#1

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: http://www.microframeworkprojects.com/index.php?title=SD_Card_Connection_Guide
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


#2

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


#3

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 http://www.tinyclr.com/forum/2/159/#/2/


#4

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”


#5

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


#6

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

Have you tried a different SD card?


#7

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!


#8

No ideas… Anybody?


#9

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


#10

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


#11

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


#12

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?


#13

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?


#14

Panda


#15

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


#16

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

Thomas


#17

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


#18

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.


#19

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


#20

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:

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

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.