Main Site Documentation

SD-Card CobraII


#1

Hi,
Can anyone tell me how to monitor the SD-Card with the latest version 4.3.5.0 ?

FEZ CobraII !!

I have try following…

        
private void SDDetect()
        {
            try
            {
                sddc = new InputPort(G120.P1_8, true, Port.ResistorMode.PullUp);


                while (true)
                {
                    Thread.Sleep(200);
                    if (sddc.Read())
                    {
                        Debug.Print("SD Card insert !");
                    }
                    else
                    {
                        Debug.Print("SD Card eject !");
                    }
                }
            }
            catch (Exception ee)
            {
                Debug.Print(ee.Message);
            }
        }

But an exception is thrown !
I can’t define the G120.P1_8 as InputPort.
Ports 0 and 2 are possible. I think that the Ports 0 and 2 are used as InterruptPort too.

It isn’t possible that I can use Port 1 as InputPort.

Is there another way to this target?

In the SDK 4.2 I can use PersistentStorgage, but I want use the latest Version 4.3.

Thx a lot.

Michael


#2

A solution to the problem is the direct access to the Register.


        private void SDDetect()
        {
            try
            {
                Register ICON_P1_8 = new Register(0x4002C0A0);
                Register DIR1 = new Register(0x20098020);
                Register MASK1 = new Register(0x20098030);
                Register PIN1 = new Register(0x20098032);
                uint value = ICON_P1_8.Value;
                uint dir1Value = DIR1.Value;
                uint pin1Value = PIN1.Value;
                uint mask1Value = MASK1.Value;

                //sddc = new InputPort(G120.P1_8, true, Port.ResistorMode.PullUp);

                while (true)
                {
                    Thread.Sleep(200);
                    if ((PIN1.Value&(uint)0x01000000) > 0)
                    {
                        Debug.Print("SD Card ejected !");
                    }
                    else
                    {
                        Debug.Print("SD Card inserted !");
                    }
                }
            }
            catch (Exception ee)
            {
                Debug.Print(ee.Message);
            }
        }

I’m still looking for a solution with the .NetMF.
Why is it not possible to assign an input port to Port1?
It is defined as GPIO !

thx a lot.

Michael


#3

Here’s another solution using the Register Interface.
I have changed the adress for the PIN1 Register.
I use the indexer now.


        private void SDDetect()
        {
            try
            {
                Register ICON_P1_8 = new Register(0x4002C0A0);
                Register DIR1 = new Register(0x20098020);
                Register MASK1 = new Register(0x20098030);
                Register PIN1 = new Register(0x20098034);

                //sddc = new InputPort(G120.P1_8, true, Port.ResistorMode.PullUp);

                while (true)
                {
                    Thread.Sleep(200);
                    if (PIN1[8])
                    {
                        Debug.Print("SD Card ejected !");
                    }
                    else
                    {
                        Debug.Print("SD Card inserted !");
                    }
                }
            }
            catch (Exception ee)
            {
                Debug.Print(ee.Message);
            }
        }

Michael


#4

@ MHSchmidt - What kind of exception is thrown?


#5

Exception System.ArgumentException - 0xfd000000 (5)

#### Message: 
#### Microsoft.SPOT.Hardware.Port::.ctor [IP: 0000] ####
#### Microsoft.SPOT.Hardware.InputPort::.ctor [IP: 0008] ####
#### GadgeteerApp11.Program::SDDetect [IP: 0037] ####

The exception is only occured at Port1.

Michael


#6

Is that a Gadgeteer project or plain NETMF?


#7

@ MHSchmidt - It looks like you are using a Gadgeteer project. If that is the case, the Cobra II creates an InputPort object internally in its Gadgeteer driver for the SD detect pin. You can access it through the Mainboard.IsSDCardInserted property.


#8

It is a Gageteer-Project…

I’m using the latest Version of SDK 2.43.1000 and the Version 4.3.5.0 of GHI.

Sorry, but I can’t find the property IsSDCartInserted or any Events.

thx a lot.

Michael.


#9

OK, I found the right funtionallity in the FEZCobraIIEco.dll.
I have to say that have a CobraIIWifi Board and I have an own Mainboard.Project for this one.

It’s possible that I can include all necessary funtions ?
I don’t found this on codeplex !

thx a lot.

Michael


#10

GHI is moving everything to bitbucket:

https://bitbucket.org/ghi_elect/gadgeteer/src/88a089a620900a2bd855bf31e2cf0a8bd805167d/Mainboards/GHIElectronics/FEZCobraIIEco/FEZCobraIIEco_43/FEZCobraIIEco_43.cs?at=master


#11

OK.

I will try it.

Thx a lot

Michael


#12

Also make sure that you are targeting 4.3 framework in the project settings.

For me it defaulted to 4.2 and the property was not there. I had manually switch to 4.3


#13

Thanks again…

I have expanded my code and it works fine.
But I have made following changes to mounted the SD-Card during the polling loop.


        public bool IsSDCardInserted
        {
            get
            {
                bool retValue = !this.sdCardDetect.Read();

                if (retValue)
                {
                    if (SDCardStorageDevice == null) MountStorageDevice("SD");
                }
                else
                {
                    if (SDCardStorageDevice != null) UnmountStorageDevice("SD");
                }

                return retValue;
            }
        }

I have Change the loop also.


        private void SDDetect()
        {
            try
            {
                while (true)
                {
                    Thread.Sleep(500);
                    if (Mainboard.IsSDCardInserted)
                    {
                        if (!Mainboard.IsSDCardMounted) Debug.Print("SD Card inserted !");
                    }
                    else
                    {
                        if (Mainboard.IsSDCardMounted) Debug.Print("SD Card ejected !");
                    }
                }
            }
            catch (Exception ee)
            {
                Debug.Print(ee.Message);
                throw;
            }
        }

I will test the behavoir of this code next time.

thx a lot again.

Michael