SPI and I2C are probably the most commonly used digital protocols to connect integrated circuits in a diverse array of products. SPI and I2C are both easy-to-use, hard-to-break serial digital protocols that are quite easy to route from a signal integrity perspective. Unlike impedance-controlled high-speed differential serial protocols, these two protocols do not have an impedance specification and will often be considered electrically short. This means that, on the PCB, the design requirements are relatively simple and there is still some freedom within the standard to tune the performance as you would like.
One of the common implementations of SPI and I2C in a PCB layout is as a protocol for reading and writing to an external Flash memory. Flash chips are a very common component in embedded systems and can offer high capacities of non-volatile memory up to Gb values. When choosing a memory chip, you'll want to match the application requirements and functionality with the bus speed you need for read and write operations in your memory chip. There is also the matter of the type of Flash memory you'll need to access (NOR vs. NAND).
SPI and I2C Comparison
The Serial Peripheral Interface (SPI) and Inter-Integrated Circuit (I2C) protocols are both simple serial digital protocols that run at low to moderate speeds. These two interfaces have some common characteristics:
- They use more than one wire for sending/receiving data
- The clock is source-synchronous, meaning there is a single trace that carries the clock line
- Other chips on the bus are addressable or toggle-able
- Most microcontrollers will have one or both of these interfaces integrated
- The signal level can be set by the core voltage given to the chip
- Neither of these interfaces has an impedance requirement
Clearly, these interfaces are very similar. They do have some important differences as summarized in the table below.
I2C |
SPI |
|
Net names |
- Serial data (SDA) - Serial clock (SCL, sometimes named SCK) |
- Master-in, slave out (MISO) - Master-out, slave in (MOSI) - Serial clock (SCK or SCLK) - Chip select (CS, optional) |
Topology |
- Broadcast bus topology |
- Shared MISO/MOSI/SCK - Star for CS pins |
Data rate |
- Standard mode: up to 100 kbps - Fast mode: up to 400 kbps - Fast mode plus: up to 1 Mbps - High-speed mode: up to 3.4 Mpbs |
- Fixed by clock window time, reaches up to 60 Mbps |
Rise/fall times |
- Depends on bus capacitance and pull-up resistor values (use RC time constant) |
- Specified for a given load impedance |
Addressing |
- Address pins fixed on each component |
- CS pins used in the main controller to toggle chips (can be toggled with GPIOs or dedicated CS pins) |
Directionality | - Half duplex | - Full duplex |
Signal driving | - Open-drain |
- Push-pull (with CMOS buffer) |
The SPI standard offers higher data rates and can run with much faster edge rates compared to I2C. Due to the use of pullups on I2C, the typically high bus capacitance, and the fact that the driving method is open-drain, I2C buses can have rise times reaching 100's of nanoseconds. SPI buses can have rise times as low as 1 ns for advanced components driving low load capacitances, which means they may exhibit transient ringing during switching. SPI lines are also much more likely to produce crosstalk because their switching speed is so fast.
Important Considerations When Choosing Between SPI and I2C for Memory Chips
Accessing NAND vs. NOR Flash Memories
In this section I don't want to get into the particulars of NAND vs. NOR Flash memories, instead I want to focus on how each is accessed with a serial protocol. Both types of Flash chips can be accessed with an SPI or I2C bus if you can procure the right memory component:
- NOR Flash - This is overwhelmingly accessed using SPI, even on smaller and slower Flash chips. Slower chips are available that can be accessed with I2C.
- NAND Flash - This is overwhelmingly accessed using a parallel bus, but chips with I2C and SPI buses are available in approximately equal number.
If you look on Octopart and use the filter features, you'll be able to locate some high-capacity memories that use either interface.
I2C to SPI Interface Bridging For Memories
If you need to convert between an I2C and SPI interface, you can use an interface bridge. These components convert the data format between these interfaces, thus a component that might only have an SPI bus can then access peripheral components that only have an I2C bus. This includes memory chips, although if the controller is only using I2C and the memory is using SPI then the speed might be limited and the receiving component might not work due to long rise times.
To overcome this limitation with I2C, it's best to use a controller with SPI, and then use the interface bridge to access a peripheral that only has I2C. Note that the SPI side will have to be clocked lower to ensure it can be used at I2C speeds. This would be done in the following topology: