More SD problems with USBizi

Hi, I have seen the threads on SD card issues but none of them seem to have been satisfactorily completed. We have a device based on USBizi which has an SD card slot but we cannot get it to work.

The _storage = new PersistentStorage(“SD”); fails after about 2 seconds with a system.exception.
We are using Sandisk 2MB cards.

In our design we do not control the power to the SD card it is powered all the time.

We connect the SD card connector to the SD lines defined in the USBizi (100 pin) user manual. The card detect switch goes to IO4 (pin 70) If we remove the card the remove interupt is fired and if we insert the card the insert interup if fired.

Our code is:
private InterruptPort SdCardInterupt;
private PersistentStorage _storage;

    //private StorageDevice _device;

    // Note: A constructor summary is auto-generated by the doc builder.
    /// <summary></summary>
    /// <param name="socketNumber">The mainboard socket that has the module plugged into it.</param>
    public SDCard()
    {
        // add Insert/Eject events
        RemovableMedia.Insert += Insert;
        RemovableMedia.Eject += Eject;

        IsCardMounted = false;
        SdCardInterupt = new InterruptPort((Cpu.Pin)USBizi.Pin.IO4, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
        SdCardInterupt.OnInterrupt += new NativeEventHandler(SdCardInterupt_OnInterrupt);

        try
        {
            if (IsCardInserted)
            {
                _storage = new PersistentStorage("SD"); //This line throws the error
                MountSDCard();
            }
        }

        catch (Exception e)
        {
        }

    }

I have checked the power to the SD card and it is 3.15V (well within spec)

I would be very grateful for any help

Best regards

Using code tags will make your post more readable. This can be done in two ways:[ol]
Click the “101010” icon and paste your code between the

 tags or...
Select the code within your post and click the "101010" icon.[/ol]
(Generated by QuickReply)

Besides the tags as Eric mentioned, your code doesn’t show where IsCardInserted is set to true.

Did you check Codeshare? We have tons of examples on how to work with SD cards.

Hi,

The IsCardInserted simply does a read on the IO pin


public bool IsCardInserted
        {
            get { return !SdCardInterupt.Read(); }
        }

This code does correctly return true when a card is present

I have seen lots of examples but of course they all do exactly what we are doing in terms of software, if you can’t call the constructor then there isn’t much else you can do!!
What would be really helpful is to understand what the contstructor does that might throw the exception…does it for example actually try and communicate with the card?

Thanks

Why do you mount it inside the constructor. Wouldn’t it be more sound to mount it when it is inserted inside your interrupt handler?

Possibly, but that certainly doesn’t stop the constructor working!!!

I can worry about better program flow once I can actually get a PersistentStorage class working!!

Do you have more information about the exception?

Hi,

The exception is:

Message:

#### GHIElectronics.NETMF.IO.PersistentStorage::.ctor [IP: 0000] ####
#### _3G_Sensor.SDCard::.ctor [IP: 0053] ####
#### _3G_Sensor._3Gmain::ProgramStarted [IP: 0005] ####
#### _3G_Sensor.Program::Main [IP: 0009] ####

A first chance exception of type ‘System.Exception’ occurred in GHIElectronics.NETMF.IO.dll

I appreciate your help
Regards

Ok, is there an inner exception and/or HRESULT value for the exception.

Check this helper class:

http://www.tinyclr.com/codeshare/entry/218

Hi,

No, I don’t get another exceptions or a HRESULT value visible in the output window

Regards

Hi,

Actually the HRESULT code in the exception is 0xffffffff

Inner exception = null

Glenn

Did you added a cap on the powerline close to the sd socket?

Yes, we have the specified 22uF, we do have some additional smoothing on the supply as it is a permenant supply to other things

Regards

Hi,

I have been looking at the SD card signals on the scope and things like CLK appear to be floating suggesting they are configured as inputs!!!

Does the USBizi automatically configure the pins when we call PersistentStorage constructor?

Also, does it check for Card present on one particular pin?

Thanks

Ate you using fez panda?

I think they have a custom board with USBizi

If so do you have a panda? You can use it as a reference.

Gus,

We have a custom board as Brett said, we used the FEZMini as a reference, we have used all the same connections to the SD card connector

In implementing directly on USBizi we of course loose all concept of ‘sockets’ so I wondered if there was something we need to do to tell USBizi to condfigure the pins for SD card use?

Regards

What firmware are you using?

Does SD work with mini?