Could someone please give me a concise explanation to how an SD card sends and receives data from a computer. Does it do this one bit at a time? How does the computer/SD card combine these individual bits into useful bytes? I can see all the pins and what they do but could someone explain how it all comes together to create the read-write functions were all use to?

- 155
- 2
- 9
-
Perhaps reading the spec will help. – Dmitry Grigoryev May 09 '16 at 14:01
2 Answers
I believe there are explanations of this on the web.
You might get a good understanding by reading code and looking at the wiring of a real project, e.g. the Arduino's SD memory card library, which can read a FAT file system. It uses a very simple hardware interface.
The datasheets for SD memory will explain how it is read and written, or you could read a tutorial, e.g. Adafruit's SD tutorial
SD card can be read and written using SPI, which uses only three wires plus power, and an enable or 'chip select' (CS) signal so that multiple SD cards could share a common three-wire bus. SPI has one data signal in each direction (DI, DO) and a clock (SCLK) to synchronise and identify valid data. SD is driven by commands, send over the SPI interface, so look at the command set for an SD card. The commands will be byte orientated as, by default, SPI is byte orientated.
The serial I/O for most host devices, from microcontroller to microprocessor is usually handled by a byte-orientated peripheral interface, but it could all be done in software by 'bit banging' serialised data over individual general purpose I/O (GPIO) pins. It'd use three for SPI, one for each of SCLK, DI and DI, and one for each SD memory cards chip select (CS).
For higher performance SD memory cards can transfer multiple bits in a single cycle, so by using 4 data signals, it can be read or written 4x faster. When the communication first starts, it starts with the three SPI signals, then a host system (e.g. computer, camera) might quickly negotiate to activate the interface with more signals.

- 10,040
- 20
- 29
-
Not exactly like that for 4 bits : There are two modes, SD and SPI. SD mode use CMD, DATA (bidir) and CLK. SPI uses CS SCLK DI and DO. Mode selection is done at power-up/reset. From the SD mode you can switch to faster modes with higher frequency (including UHS modes) and/or a wider, 4 bits bus. – TEMLIB May 07 '16 at 20:27
-
@TEMLIB - thanks very much. Are you certain that's the only way? I'm willing to believe you because I've only used SPI. However my (several years ago) reading of, probably ST, SD peripheral interface documentation was that initial contact was 'three signal' then an 'upgrade' to 'full-width'. If you're reasonably confident, I'll correct. – gbulmer May 07 '16 at 20:33
-
The official specification (without the DRMs part) is available. For example : http://users.ece.utexas.edu/~valvano/EE345M/SD_Physical_Layer_Spec.pdf. SPI page 104, look at the state diagrams. SPI mode is a legacy of MMC cards. I also once made a article on my website... – TEMLIB May 07 '16 at 20:42
-
@TEMLIB - Thank you very much for your help. It's getting late here, so I'll look tomorrow. – gbulmer May 07 '16 at 22:03
For a manual on microSD card specifications, search for "Transcend" on the web and download this PDF file: TS256M~2GUSD. It is a 756KB file, so it covers all the fine details of the SD memory itself.
It follows the SD card specification v1.1 and the SD Association File System Specification. Follow the Arduino's instructions for their interface and drivers. Use the Transcend manual for the details of SD chip itself.
If you buy a specific type and capacity of microSD chip, make it a point to download the technical PDF file for the SD chip. It may have a much larger storage capacity and therefore have the correct mapping of the memory block/page sizes.
Be sure the SD card socket is custom built into a PCB, because the clock rate can be as high as 50 MHz.

- 1,676
- 3
- 17
- 23
-
Re: "Follow the Arduino's instructions for their interface and drivers". Do you have a source for that? – Peter Mortensen May 08 '16 at 22:24
-
@PeterMortensen. That would be a moot point. If you buy an Arduino product that material will be packed with it. or worst case is they provide a link to a pdf to download. Every maker of a chip or DIY board supplies these details, in one format or another, or they would be out of business very quickly. The OP did not specify what model of Arduino he bought, and did not need to. – May 09 '16 at 00:01