Reading/Writing SD/MMC Cards Via SDI

I'm stuck at work, but I keep running across these cool things to try with my Arduino, but don't have the time yet...

These two links describe how to use an old floppy drive connector as an SD card slot and tell how you can use one in MMC mode using SPI and five pins (3.3V, GND, clock, data in, and data out). As it happens, I had been thinking about how to store some configuration data for an Arduino program and update it without connected back to the computer or adding an interactive input device.

Does anyone of any reason why this technique wouldn't work with an Arduino program? If I'm reading all of this right, it appears that you could write a bunch raw data to a card (maybe using a tethered Arduino), then read the card from another program running standalone. This would also be great for long-term data logging, wouldn't it?

http://uanr.com/sdfloppy/

http://wiki.openwrt.org/OpenWrtDocs/Customizing/Hardware/MMC

I was thinking of eventually getting around to doing this. :slight_smile:
Should work fine.

The trickiest part is the file system.
If you want it user friendly, you need to create files and obey the rules of FAT16 at least.
Basically only Linux users would be able to use it if you did raw reading and writing.

I was thinking of writing the raw data with the Arduino as well. If you used it for data an Arduino program could read the card back and write the data serially, right?

Of course, supporting a file system would be even better, but I was thinking of keeping it simple.

I tried it once. There must be a topic somewhere here. But I lost my patience before it worked. If it works it will be without filesystem though. I switched to dataflash. (memory from atmel). But that is something you can only use with arduino, you can't take the memory out and put it in a pc.

There is someone here, Nick, who got the vinculum working. With that you have an USB interface which you can use with a memory stick, that is even better. He wanted to post it in the playground but I guess he didn't have time yet to do it.

Ok lets make a deal. You get the SD card working, I'll make a dodgy and small FAT implementation. ;D

I've got a 16mb SD card which I can use.

Bingo. The work has already been done for us. :slight_smile:

Now to convert that for use on the Arduino....

Bingo. The work has already been done for us. :slight_smile:

captain.at - captain Resources and Information.

Now to convert that for use on the Arduino....

Seems easy doesn't it? good luck!

Well I've wired up my floppy drive SD card socket (damn. I didn't realize I still had so many of them) and I've realized that I don't have a multimeter to test it. :frowning:
I'll go buy one tomorrow hopefully.

Until then, I'm going to be praying that this works. :slight_smile:

My soldering sucks. ;D

Going to have to buy some pin headers and heat shrink tubing tomorrow as well.
I cant get the tinned wires to stick in the Arduino's ports.

You will learn eventually.

Solder some legs from a LED or something to your flatcable, then you can insert it in the headers. When you go out shopping, buy a lot of headers pins. Very handy, especially for flatcable.

You will learn eventually.

I know how to solder. I just haven't done it in about a year. :slight_smile:
I'm primarily a programmer.

Ok I'm looking at someone else's code which uses a lot of this:

    /* initialize SPI with lowest frequency; max. 400kHz during identification mode of card */
    SPCR = (0 << SPIE) | /* SPI Interrupt Enable */
           (1 << SPE)  | /* SPI Enable */
           (0 << DORD) | /* Data Order: MSB first */
           (1 << MSTR) | /* Master mode */
           (0 << CPOL) | /* Clock Polarity: SCK low when idle */
           (0 << CPHA) | /* Clock Phase: sample on rising SCK edge */
           (1 << SPR1) | /* Clock Frequency: f_OSC / 128 */
           (1 << SPR0);
    SPSR &= ~(1 << SPI2X); /* No doubled clock frequency */

Does anyone know of a good reference for this stuff?

Once I know how to convert it to Arduino style code, I should be dumping data from a SD card. :slight_smile:

hi cheater,

take a look here: << - Arduino Reference

good luck!

Ok I'm looking at someone else's code

Once I know how to convert it to Arduino style code, I should be dumping data from a SD card. :slight_smile:

Absolutely! :smiley: This is what I used:

  SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0)|0<<SPI2X;

But remember: I didn't get it working before I lost my patience with it.

take a look here: << - Arduino Reference

Should have made myself clearer.

I need help with the letters, not the bit shifting. :slight_smile:
E.g. SPCR, SPE, etc...

Directly dealing with the SPI controller in the AVR is sort of beyond the scope of the Arduino environment, so I'm not sure there is an "arduino style" to follow. The symbols you're looking for (SPE, MSTR, etc) are defined in an include file <avr/iom8.h> or <avr/iom16.h>, which the Arduino environment already includes for you at the beginning of the sketch, and when I copied the code segment you mentioned into the setup() of the led_blink example, it worked fine.

For the meanings of the symbols, you'll need to look in the Atmel data sheets for the parts:
http://www.avrfreaks.net/index.php?module=Freaks%20Files&func=viewFile&id=1242&showinfo=1

Probably easiest not to change it then? Ok. :slight_smile:

[EDIT]
Am I correct in thinking that the 3.3v rail is from the USB port?

That will mean that Arduino needs to be USB powered to read from the MMC card since it doesnt like 5v.

I also forgot to buy a multimeter which means I cant test it. Damn.
[/EDIT]

[EDIT]
Will I need pull up/down resistors?
This schema for a PIC shows resistors on the data input pins.
http://www.captain.at/electronics/pic-mmc/mmc.png
[/EDIT]

Update: Tomorrow I'll get a multimeter among other things and then I'll start testing. :slight_smile:
Hopefully I'll be dumping data this time tomorrow.

Yay! I got somewhere. :smiley:
Not sure where exactly but the card is talking to me which is a good thing.

This is the output of my code:

SPI Set Up
Waiting............
Resetting Card.
Card is getting ready.
Ready! Setting block size.
Max Speed
Getting device info
..................
Manufacturer: 0
Date: 0/0
Serial: 0
Size: 4
Format: 0
End!

I dont know why everything is zero except the size.
The size of the card I'm using is 16mb so maybe the size is 4mb * that value.

Now to try and pull some actual data off the card. :slight_smile:

Having trouble getting data from the card. All I get are 0's. :frowning:

Here is my setup: