Electronic – How does an SD card communicate with a computer?


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?
The labeled pins of an SD card and Micro SD card

Best Answer

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.