Works on this device
Spi Timing Calculator
SPI is a serial bus with a clock (SCK), data lines and a chip select. This calculator works out the clock a divider gives, how long a transfer takes and how much data the bus carries, what the four SPI modes mean, and how fast the clock may be when you read data back.
Enter your values
Check these values
Your values are worked out in this browser. They are not sent to a server.
Your result will show here
Fill in the values, then choose the button below them.
Your result
How it was worked out
How to use this calculator
- Choose what you want: the clock from a divider, the time of a transfer, the four modes, or the highest clock for reading.
- Enter the values from the data sheets of the controller and the device: the source clock and the dividers, the chip select times, the output delay and the setup time.
- Choose Calculate. Under More options you can add gaps and chip select times to a transfer.
The formulas
- Clock: SCK = source clock ÷ divider. One bit takes one clock period.
- Transfer time = lead time + words × bits × clock period + (words − 1) × gap + lag time.
- Throughput = bits in a transfer ÷ (transfer time + chip select high time).
- Modes: mode = 2 × CPOL + CPHA. CPOL sets the idle level of the clock; with CPHA 0 data is read on the first clock edge, with CPHA 1 on the second.
- Highest clock for reading: data is changed on one edge and read on the other, half a period later with a 50% duty cycle. So half a period must cover the wire delay out, the output delay of the device, the wire delay back and the setup time: f max = 0.5 ÷ (output delay + setup time + 2 × wire delay).
The four SPI modes
| Mode | CPOL | CPHA | Clock when idle | Data read on | Data changed on |
|---|---|---|---|---|---|
| Mode 0 | 0 | 0 | Low | Rising edge (first) | Falling edge (second) |
| Mode 1 | 0 | 1 | Low | Falling edge (second) | Rising edge (first) |
| Mode 2 | 1 | 0 | High | Falling edge (first) | Rising edge (second) |
| Mode 3 | 1 | 1 | High | Rising edge (second) | Falling edge (first) |
Worked examples
72 MHz ÷ 8 gives a 9 MHz clock, 111.1 ns per bit. For a device that allows 10 MHz, the dividers 2, 4, 8 ... give 36, 18 and 9 MHz, so 8 is the smallest divider that is allowed.
Four 8-bit words at 8 MHz with 50 ns lead time, 50 ns lag time and 100 ns with chip select high: the data takes 32 × 125 ns = 4 µs, the transfer 4.1 µs, and the bus carries 32 bits every 4.2 µs, which is 7.62 Mbit/s.
Reading back from a device with 25 ns output delay, a controller with 5 ns setup time and 1 ns of wire each way: the round trip is 32 ns, so half a period must be at least 32 ns and the clock at most 15.6 MHz.
Limits you should know
- Makers name the modes and the clock edges in different ways. Check the SPI chapter of each data sheet; the controller and the device must use the same mode.
- The timing is ideal: no clock jitter, a 50% duty cycle unless you change it, and the wire delay as you type it. Signal quality on long wires is not covered.
- Software time between transfers is often larger than the bus time. Include it in the chip select high time.
- For a UART link, see the Baud Rate Calculator. For an I²C bus, see the I2c Pullup Resistor Calculator.