Mini and SD via SPI - Netduino Mini - Netduino Forums
   
Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Mini and SD via SPI


  • Please log in to reply
3 replies to this topic

#1 Quiche31

Quiche31

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts
  • LocationFrance

Posted 30 November 2010 - 11:42 PM

Hi there

I am trying to connect my Netduino Mini to a MikroE MMC/SD reader via SPI, using the new firmware v. 4.1.1.0 a3, and the sample code provided by Chris

The error that I got is a SPI error, which is reported by my analyzer Salae Logic as "The initial state of the CLK line does not match the settings". I have googled for this error but have not found any reference. As you can see on the diagram below,
CS goes low, and SPCK pulses high. So I am wondering what is wrong with this. Maybe this will ring a bell in the case you have seen this error already.

Available information: breadboard schema and chronogram.
I have also attached (at the bottom of the post) the Salae Logic file, that can be replayed. Finally, here is the code, which is pretty much what Chris provided:

using System;
using System.Threading;
using Microsoft.SPOT;
using System.Text;
using System.IO;
using System.IO.Ports;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoMini;
using SecretLabs.NETMF.IO;

namespace NetduinoMiniApplication1
{
    public class Program
    {

        public static void Main()
        {
            // default CS pin on Netduino Mini is Pin 13:
            StorageDevice.MountSD("SD1", SPI_Devices.SPI1, Pins.GPIO_PIN_13);

            string[] directories = System.IO.Directory.GetDirectories(@"\");
            Debug.Print("directory count: " + directories.Length.ToString());

            for (int i = 0; i < directories.Length; i++)
            {
                Debug.Print("directory: " + directories[i]);
            }

            string[] files = System.IO.Directory.GetFiles(@"\SD1");
            Debug.Print("file count: " + files.Length.ToString());

            for (int i = 0; i < files.Length; i++)
            {
                Debug.Print("filename: " + files[i]);
                FileStream fs = new FileStream(files[i], FileMode.Open, FileAccess.Read, FileShare.None, 512);
                StreamReader sr = new StreamReader(fs);
                Debug.Print("contents: " + sr.ReadToEnd());
            }
        }
    }
}

Finally, the assemblies that I referred to are:
Microsoft.SPOT.Hardware
Microsoft.SPOT.IO
Microsoft.SPOT.IO.Native
mscorlib
SecretLabs.NETMF.Hardware
SecretLabs.NETMF.Hardware.NetduinoMini
SecretLabs.NETMF.IO
System.IO


Let me know if this rings a bell. Otherwise I'll keep investigating, using a different SPI device, as I suspect that my problem is a SPI issue, not related to the MMC/SD module.

Thanks
JP

Attached Files



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 30 November 2010 - 11:46 PM

What size is your SD card? Is it <=2GB? SDHC? Also, is it formatted with FAT16 or FAT32? Chris

#3 Quiche31

Quiche31

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts
  • LocationFrance

Posted 30 November 2010 - 11:55 PM

What size is your SD card? Is it <=2GB? SDHC? Also, is it formatted with FAT16 or FAT32?


This is a SDHC 4GB under FAT16... now I remember having read something about 2GB max. If so I may have a problem later (but I'd replace with a 2GB). However I don't see a SPI connection successfully established. I forgot to send the exception seen in the debugger:

The debugging target runtime is loading the application assemblies and starting execution.
Ready.

'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.1\Assemblies\le\mscorlib.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.1\Assemblies\le\Microsoft.SPOT.Native.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.1\Assemblies\le\Microsoft.SPOT.Hardware.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.1\Assemblies\le\Microsoft.SPOT.Hardware.SerialPort.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.1\Assemblies\le\Microsoft.SPOT.IO.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.1\Assemblies\le\System.IO.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Secret Labs\Netduino SDK\Assemblies\v4.1\le\SecretLabs.NETMF.Hardware.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'SecretLabs.NETMF.Diagnostics'
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Secret Labs\Netduino SDK\Assemblies\v4.1\le\SecretLabs.NETMF.IO.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Data\Perso\0.Electronics\3.Netduino\_Projects\Mini\NetduinoMiniApps\NetduinoMiniApplication1\bin\Debug\le\NetduinoMiniApplication1.exe', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Secret Labs\Netduino SDK\Assemblies\v4.1\le\SecretLabs.NETMF.Hardware.NetduinoMini.dll', Symbols loaded.
The thread '<No Name>' (0x2) has exited with code 0 (0x0).
    #### Exception System.IO.IOException - CLR_E_VOLUME_NOT_FOUND (1) ####
    #### Message: 
    #### SecretLabs.NETMF.IO.StorageDevice::SDSPI_Mount [IP: 0000] ####
    #### SecretLabs.NETMF.IO.StorageDevice::MountSD [IP: 0016] ####
    #### SecretLabs.NETMF.IO.StorageDevice::MountSD [IP: 0008] ####
    #### NetduinoMiniApplication1.Program::Main [IP: 000a] ####
A first chance exception of type 'System.IO.IOException' occurred in SecretLabs.NETMF.IO.dll
An unhandled exception of type 'System.IO.IOException' occurred in SecretLabs.NETMF.IO.dll

Thanks Chris!

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 01 December 2010 - 12:10 AM

Quiche31, A FAT16 or FAT32-formatted 2GB SD card will probably work without issue. SPI is pretty straightforward when the settings are already configured... Please let us know if it works or if it doesn't work. Either way, we want to make sure you're up and running! Chris




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.