André's 8-bit Pages  Projects  Code  Resources  Tools  Forum
(by Google)

SPI Information

In my CS/A65 computer I use the SPI interface to connect and use MMC- and SD-Cards.
  •  
    2012-01-01 Added link to Daryl's SPI65 and my own SPI65B solution.
  •  
    2011-03-6 Moved the content from the CS/A MMC page here.
 

SPI

SPI means "Serial Peripheral Interface Bus" and is a very simple four-wire protocol. Some of the advantages are:

  • Each signal is single direction, there are no bi-directional signals
  • It is a synchronous bus and clock is controlled by a single source.
  • It is byte-oriented
One of its disadvantages is: it is not exactly well specified:

There are these four lines:

SignalDirectionDescription
/SELSPI Master -> SPI SlaveIf low, the selected device is selected. A master may have multiple of those outputs, but a slave has only one input
CLKSPI Master -> SPI SlaveClock for data transfers
MOSISPI Master -> SPI SlaveData from master to slave
MISOSPI Slave -> SPI MasterData from slave to master
Beyond that the CLK levels and at which CLK transition the data is transferred is not defined!

SPI Modes

For this reason there are different possibilities:

  • CPOL=0/1: base value of the clock. I.e. the level of the CLK signal when no data transfer is going on.
  • CPHA=0/1: The transition of the clock (leading or trailing edge) on which the data is transferred
This results in the fact that there are four SPI modes,
ModeCPOLCPHA
000
101
210
311
Unfortunately some devices only understand a single mode, and different from other devices, so a master should be able to handle all modes.

Links

MMC-Card and SD-Cards are cheap means of getting large amounts of storage memory nowadays. And they are getting larger and cheaper every day. Those cards are based on flash memory and can be found in digital cameras, navigation systems, and many more.

Unfortunately the MMC- and SD-Card protocols are not free, however a certain amount of intelligence has been gathered and is available on the web:

as well as in datasheets for MMC or SD-Cards found on the producers homepages.

MMC/SD SPI mode

Newer MMC and especially SD-Cards use a mode where more than a single bit is transferred per clock. In fact the cards have four data lines that are used in native mode. This mode is however more complicated. But, we are lucky, all cards still support the SPI mode, that they can enter upon startup when instructed to do so. And this is what the driver does.

One problem I had in the beginning was that the datasheets mentioned the data transfer on the rising edge of the clock, but not what clock level would be correct. By experimentation I found that MMCs and SD-Cards use mode 0.

 

SPI Links

  • Wikipedia The wikipedia article on SPI.
  • Daryl Rictor's SPI65 If you click on "65SPI" on the left navigation on that page, you find Daryl Rictor's 65SPI solution, a Xilinx 9572 CPLD-based SPI solution.
  • SPI65/B Based on the specifications of Dary's solution, I have re-implemented it in VHDL with some modifications. See the descriptions after the link.
 

Disclaimer

All Copyrights are acknowledged. There is no warranty attached to the information on these pages.

Contents last modified 2012-01-04.

Return to Homepage

Last modified: 2012-01-04
share
follow

Follow my 8-bit tweets on Twitter (In new window)

discuss

Discuss my site on this 6502.org forum thread

(Forum registration required to post)

hot!

Dive into the retro feeling and build yourself a Commodore PET replica

Need more speed? Speed up your 6502 computer with this 10 MHz 6502 CPU accelerator board

Interested in electronics design? Look at the design lesson I got from Bil Herd, the hardware designer of the C128

Want 64bit? - pimp the 6502 with the 65k processor design!