Posts

Showing posts from July, 2010

Accessing SD cards via SPI bus

There are various examples of accessing standard SD cards via the SPI bus (Microchip has one in their example code) but getting to the basics of how to implement your own is tricky! Here is a simple how-to, I've tried to show WHY you have to do certain things to make it clear what is happening.... - I'm assuming you have the SD card correctly connected onto the SPI bus and the chip select line (I'll call it CARD_CS) also setup correctly. [SPI BASICS] The SPI bus clock only runs while data is being clocked in/out. Data moves in both directions at the same time so if you clock 'out' byte 0xB3 you're 'in' buffer will change to whatever is on the input bus. If the device you are talking to did not send anything back at that time, the value will be 0x00. The SD card keeps things simple by (normally) not sending anything back until you have finished sending it a commend. This avoids the need to handle 'in' and 'out' comms at the same time... As