Reading an SD card (FAT16).

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
AndrewBack
Member
Posts: 10
Joined: Wed Apr 28, 2010 3:07 pm

Reading an SD card (FAT16).

Post by AndrewBack »

Hello,

I have an XC-2 and a PCB mounted SD socket like:

http://cgi.ebay.co.uk/Secure-Digital-SD ... 0088582404

How would I go about getting started with cabling this and then reading from the card? I notice that Berni's audio player uses some XMOS (c) code for this but wasn't sure where to go for the canonical version, and was hoping that with the XMOS archive of this there would be documentation and example code.

Regards,

Andrew


User avatar
Berni
Respected Member
Posts: 363
Joined: Thu Dec 10, 2009 10:17 pm

Post by Berni »

Feal free to use the code i used. I got it off the old xlinkers site, but note that the code is not really super fast.
User avatar
AndrewBack
Member
Posts: 10
Joined: Wed Apr 28, 2010 3:07 pm

Post by AndrewBack »

Hi Berni,

Thanks for the reply. Is the code in your project identical to:

http://archive.xmoslinkers.org/node/227 ?

Where can I find the pinout for cabling the SD socket to the XC-2?

Is the slow speed because this is simply a reference implementation and not optimised, or is it to do with a particular SD mode that has been implemented? Or something else...

And can someone from XMOS clarify the license situation with this code. The files assert that it is copyright XMOS but give no indication as to the licence, so it's impossible to know what you can do with it.

Regards,

Andrew
User avatar
Berni
Respected Member
Posts: 363
Joined: Thu Dec 10, 2009 10:17 pm

Post by Berni »

Yeah thats the code i used for it. Its quite easy to get working.

Look around the code to see where it defines a pin on the xcore and change it to whatever pins you want your card on. (from memory i think its right on top of the main source file)

First speed impact is that it uses the simpler SPI interface instead of the ~4 times faster 4bit bus.Then also the code is not fully optimized for speed. For most uses tho its plenty fast. One other down side is that it only does FAT16 so anything over 4GB wont work and it only works with short file names, but that usually is no big deal.
User avatar
williamk
Experienced Member
Posts: 114
Joined: Fri Oct 01, 2010 7:47 pm

Post by williamk »

Just curious, how slow is reading and writing to a SD card? As I was wondering on using one as an external memory device for audio-samples. And if its too slow, what other solution should I seek for dealing with audio-samples?

Thanks, Wk
Wusik Dot Com (http://www.Wusik.com)
William-K.com (http://www.William-K.com)
User avatar
Berni
Respected Member
Posts: 363
Joined: Thu Dec 10, 2009 10:17 pm

Post by Berni »

Well it is fast enough to play back 96Khz WAV files, so its not completely slow, but it wont go anywhere near to the speed advertised on the cards package.
User avatar
AndrewBack
Member
Posts: 10
Joined: Wed Apr 28, 2010 3:07 pm

Post by AndrewBack »

Berni wrote:Yeah thats the code i used for it. Its quite easy to get working.

Look around the code to see where it defines a pin on the xcore and change it to whatever pins you want your card on. (from memory i think its right on top of the main source file)
You'll have to excuse my ignorance but this is a first for me in many respects...

You're code assigns pins for SD cmd, clk, dat and rsv. On my SD holder PCB [1] I think I can find the right connections for cmd and clk, but I have a DAT0, DAT1 and DAT2, whilst I don't seem to have a pin marked "RSV". And are any resistors required or is it just a simple straight connection? I assume that I'll also need to hook up the card to the GND and 3v3 provided on the XC-2 port?

Regards,

Andrew

[1] http://www.byvac.co.uk/bv/datasheets/BV ... aSheet.pdf
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

Hi Andrew

Normally using SPI you have a Clock ,Master in serial out, Master out serial in and a Device select. with an SDCard you also need to observ card detect and write protect (CDi,WP) My guess therefore would be:

From Xmos POV
Output Clock = clk pin5 equates to Berni's clk
Output MOSI = CMD/DI pin 2 equates to Berni's cmd
Input MISO = CD/DAT3 pin 1 I'm guessing equates to Berni's rsv (receive?)
Output Device select = NC

*Because devices select is not used no other spi peripherals can be connected to these pins.
*You need to read CDi and WP to detect a card and to control write access, these are inputs to the Xmos.

Berni?
User avatar
AndrewBack
Member
Posts: 10
Joined: Wed Apr 28, 2010 3:07 pm

Post by AndrewBack »

Hi Al,

You listed 3 pins: CMD, CLK and RSV. Berni also has a DAT, making four.

And do you know if I need pull-up/down resistors?

Regards,

Andrew
User avatar
Berni
Respected Member
Posts: 363
Joined: Thu Dec 10, 2009 10:17 pm

Post by Berni »

I checked the part of the code that does spi and the rsv seams to be used as a CS pin. Whoever wrote the example should have named those pins better.

So it goes like this:
clk = 6 CLK/SCLK
cmd = 2 CMD/DI
dat = 7 DAT0/DO
rsv = 1 DAT3/CS