28X1 via SPI to SD card

profmason

Member
Since I just got the 28X1 parts I thought I would try to interface an SD card to the 28X1 via the new SPI commands. I don't have anything working yet, but I thought I would post my thoughts and look for suggestions. I put the card in a socket and powered it. I hooked up the clk, spin and spo lines (Via voltage dividers to drop these to 3.3 V). I used another pin to control the CS line. (Again dropped to 3.3V)
I tried the sample code from the SPI tutorial:
symbol cs = 7

init:
hspisetup spimode11e, spimedium ‘ spi mode 1,1
low cs ‘ enable chip select
hspiout (6) ‘ send write enable
high cs ‘ disable chip select

low cs ‘ enable chip select
hspiout (1,0) ‘ remove block protection
high cs ‘ disable chip select
pause 5 ‘ wait write time
main:
low cs ‘ enable chip select
hspiout (6) ‘ send write enable
high cs ‘ disable chip select

low cs ‘ enable chip select
hspiout (2,0,5,25) ‘ write 25 to address 5
high cs ‘ disable chip select
pause 5 ‘ wait write time of 5ms

low cs ‘ enable chip select
hspiout (6) ‘ send write enable
high cs ‘ disable chip select

low cs ‘ enable chip select
hspiout (3,0,5) ‘ send read command, address 5
hspiin (b1) ‘ shift in the data
high cs ‘ disable chip select

low cs ‘ enable chip select
hspiout (4) ‘ send write disable
high cs ‘ disable chip select
sertxd (#b1)
pause 1000
goto main

I either got 255 off b1 or 0 depending on how things were powered.

** Note the code as presented is missing the definition of cs.
Then I started in on the datasheet:
http://web.archive.org/web/20041029000445/http://www.sandisk.com/pdf/oem/ProdManualSDCardv1.9.pdf

I am hoping someone else has done this already and will save me a lot of grief!
(Or maybe I will just stick with the 24LC EEPROMS which work great!)
have fun,
mmason
 

hippy

Technical Support
Staff member
I have done some MMC interfacing and I believe it was demonpicaxeguy who was looking at SD interfacing.

The first thing is that you cannot simply throw a bit stream at MMC or SD and expect it to work.

Hardware-wise the interfacing is relatively simple and as you've noted is 3.3V only and using 5V could destroy the card. The easiest way to avoid having to use any voltage conversion is to run the PICAXE at 3.3V.

Software-wise you have to implement the MMC/SD protocol which is more than just one 8-bit byte per command and response. There's also an initialisation sequence which must be gone through before you can actually communicate with the card proper. MMC is easier ( a subset ) in this respect than SD and I'd suggest getting MMC working before expanding the software to support SD.

The datasheet you have is a definitive SD spec and needs to be studied and understood in depth to succeed. Until something is working it is hard to tell what isn't so it <i>will </i> be a frustrating and time-consuming project if you've never done this before or do not have a storage scope or logic analyser.

A Forum Search should find more info on MMC/SD card interfacing ( my brief search didn't ), and I have this was-working, seems not to be now, PICAXE-18X example code which shows how complex an MMC driver can get, although the principles are reasonable straight forward ...

http://homepage.ntlworld.com/the.happy.hippy/picaxe/mmc.txt

An easier alternative is to stick with I2C Eeprom ( now available at up to 128Kx8 ) or look at the Viniculum USB-stick interface which Rev-Ed sells and can be controlled by serial.
 

profmason

Member
Thanks Hippy, I love the I2C eeproms but haven't used anything over 32Kx8. I saw that the USB memory stick adaptor was for sale, but haven't found a US supplier yet. I will put &quot;look at MMC specs for interface to Picaxe&quot; on my to do list....
 

demonicpicaxeguy

Senior Member
yep it was me with the sd card interfacing
i haven't had much luck with it and have since given up temporarily as i have had some good success with it another way using a quicker chip and i've simply been using it
but i'm going to have another crack at it with a 28x1 as soon as they arrive

i think the problem sd card wise is that the picaxe might not be quick enough to meet the clocking times and voltage seems to be a big issue as well so hopefully we'll have som success with it soon

for now though i would suggest some kind of module there are loads of them around but try to stick to the spi ones as with them you don't run into bufering problems.
 

pao

New Member
profmason,

Official PICAXE US distributor World Educational Services has the vdrive2 module, but backordered (I'm waiting on mine). Mouser has them as well. I was originally looking at doing an MMC interface for a datalogger until this popped up, and since the vdrive handles all the filesystem stuff, I think it will be a whole lot easier to implement.
 

martinn

Member
Dontronics lists VDRIVE2 for $38 Australian

http://www.dontronics-shop.com/product.php?productid=16654&amp;cat=321&amp;page=1#prices
 
Top