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.
I finally got a nice little 2GB card for my netduino plus. I formated it to use FAT32 and I tried many code examples that are listed around here. With this code:
File.WriteAllBytes("\\SD\\text.txt", new byte[] { 4, 3, 2, 1 });
I get this error:
#### Exception System.IO.IOException - CLR_E_INVALID_DRIVER (1) ####
#### Message:
#### Microsoft.SPOT.IO.NativeIO::GetAttributes [IP: 0000] ####
#### System.IO.FileStream::.ctor [IP: 005c] ####
#### System.IO.File::WriteAllBytes [IP: 0012] ####
#### SD_Card.Program::Main [IP: 0014] ####
A first chance exception of type 'System.IO.IOException' occurred in System.IO.dll
An unhandled exception of type 'System.IO.IOException' occurred in System.IO.dll
also this: Debug.Print(File.Exists("\\SD\\text.txt").ToString()); returns false. but its there!
Omar,
Try two things really quick:
1. Try formatting the SD card using FAT16. Any difference?
2. If you use System.IO.Directory.GetDirectories(@"\"), does it show the SD directory as available? If not, the card is failing to mount.
Chris
1. Try formatting the SD card using FAT16. Any difference?
2. If you use System.IO.Directory.GetDirectories(@"\"), does it show the SD directory as available? If not, the card is failing to mount.
Chris
I got the following exception both before and after formating to FAT16:
#### Exception System.IndexOutOfRangeException - 0xa9000000 (1) ####
#### Message:
#### SD_Card.Program::Main [IP: 0009] ####
A first chance exception of type 'System.IndexOutOfRangeException' occurred in SD Card.exe
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in SD Card.exe
What can I do about this failure to mount?
EDIT:
I did this: string[] dirs = System.IO.Directory.GetDirectories(@"\"); and dirs is empty after executing that line.
If you execute the following code with your card inserted (and also ejected), does the debug output in your Output window properly reflect the insertion state of the card?
OutputPort SdPower = new OutputPort((Cpu.Pin)25, false); // ensure that the SD card is powered
InputPort sdDetected = new InputPort((Cpu.Pin)57, false, Port.ResistorMode.PullUp);
Debug.Print("sd detected: " + (!sdDetected.Read()).ToString());
sdDetected.Dispose();
If this shows that your card is inserted/ejected appropriately, then unfortunately it's probably an issue with the MicroSD card. One or more of the MicroSD card manufacturers re-labels cards from multiple manufacturers. Do you happen to have a SanDisk or other MicroSD card laying around?
If you execute the following code with your card inserted (and also ejected), does the debug output in your Output window properly reflect the insertion state of the card?
OutputPort SdPower = new OutputPort((Cpu.Pin)25, false); // ensure that the SD card is powered
InputPort sdDetected = new InputPort((Cpu.Pin)57, false, Port.ResistorMode.PullUp);
Debug.Print("sd detected: " + (!sdDetected.Read()).ToString());
sdDetected.Dispose();
If this shows that your card is inserted/ejected appropriately, then unfortunately it's probably an issue with the MicroSD card. One or more of the MicroSD card manufacturers re-labels cards from multiple manufacturers. Do you happen to have a SanDisk or other MicroSD card laying around?
Chris
OH darn, yup. so I guess I need to find a new micro sd card.... have you tested any cards? if so let me know which cards are known to work.
OH darn, yup. so I guess I need to find a new micro sd card.... have you tested any cards? if so let me know which cards are known to work.
We've tested a bunch of MicroSD cards, and almost all <=2GB cards work. Kingston is a bit of a wildcard since they reportedly rebrand various cards from other manufacturers...so you don't know what care you're getting. More details here.
I am currently using 256MB and 2GB SanDisk cards in my Netduino Plus.
We've tested a bunch of MicroSD cards, and almost all <=2GB cards work. Kingston is a bit of a wildcard since they reportedly rebrand various cards from other manufacturers...so you don't know what care you're getting. More details here.
I am currently using 256MB and 2GB SanDisk cards in my Netduino Plus.
But my point here is that I got sd detected: True in both instances i.e. when the card was in and again when ejected!! I expected the result to be False with no card inserted. To check I unplugged the N+ before running the code again but got the same result. Is this to be expected? Is \ROOT the card ?
I bought the card yesterday at the local supermarket, I assumed it was pre formatted!!
Hi alanb,
The SD Detect works via a mechanical mechanism on the SD card slot. This mechanism is connected directly to pin "57". Reading that pin directly should return real-time results of insertion/ejection.
If you do Directory.GetDirectories(@"\"), do you see \SD even when the card is not inserted? That is the "true test" of valid card detection.
Card insertion/ejection detection is one of the dozens of tests done at Secret Labs before we ship a Netduino Plus...but it's possible that the detection circuitry wore out, got damaged, etc. We built the firmware to be resilient to that (failing gracefully during mounting if it thought a card was inserted). But we also offer a 30-day warranty.
Chris
Sorry for the Newbie question but which assembly contains Directory. I cant seem to find it.
Alan
I think you'll find it in System.IO. You may also need to add a reference to the DLL.
Forgive me if you already know this but to add an assembly;
Right click on the references and select Add Reference
In the new dialog select browse to the directory holding the assemblies. On my machine this is C:\Program Files\Microsoft .NET Micro Framework\v4.1\Assemblies\le
Select the System.IO.dll file and add this to the project.
alanb
Please tell us if your 4GB card works, normally they don´t (mine Sandisk 4 GB did not work).
If it should work, give us some more details of model and so on.
/Jan Olof
NETMF: v4.1.2821.0 on NetduinoPlus
I tried to run the code suggested above on v4.1.2821.0:
"...
OutputPort SdPower = new OutputPort((Cpu.Pin)25, false);
InputPort SdDetected = new InputPort((Cpu.Pin)57, false, Port.ResistorMode.PullUp);
..."
I get the following Exception (with or without SD Card present:
#### Exception System.Exception - CLR_E_PIN_UNAVAILABLE (1) ####
#### Message:
#### Microsoft.SPOT.Hardware.Port::.ctor [IP: 0000] ####
#### Microsoft.SPOT.Hardware.OutputPort::.ctor [IP: 0006] ####
#### namespace_Lib_SD.Lib_SD::Start [IP: 001f] ####
#### NetduinoPlusLibrary.Program::Main [IP: 009c] ####
A first chance exception of type 'System.Exception' occurred in Microsoft.SPOT.Hardware.dll
An unhandled exception of type 'System.Exception' occurred in Microsoft.SPOT.Hardware.dll
I had a look at the schematic and tried to relate to the code above.
PB25-(71)-<< (input) /MICRO_SD_CARD_INSERTED (???<--->???) (Cpu.Pin)57
PA25-(59)->> (output) /PWR_CTRL_uSD (???<--->???) (Cpu.Pin)25
Is there some reference lookup table that relates the Schematic pinouts to the Cpu.Pin references?
Aside:
I heard that a lot of 'clone' SD cards 1GB., 2GB etc are actually fitted with a 64KB memory and addressing is overlayed. The only way to test integrity of the uSD is to copy a 1GB or 2GB file(s) on to the uSD and copy it back to the PC, and do a file compare (Beyond Compare)!.
PS: Other than this have my class reading and writing using StreamReader/StreamWriter perfectly well.
Hi Earthed,
The power and detect pin are used behind the scenes by the .NET Micro Framework. If you have a card inserted, .NET Micro Framework may give you angry exceptions since the pins are already being used for something
Chris