Two chips, four wires — how do they talk? 两块芯片,
怎么用四根线
说话?

No hardware background needed. This page takes one transfer, one beat at a time. 不需要任何硬件基础。这一页把一次传输拆成一拍一拍来看。

SCLK MOSI MISO CS
Four wires, four jobs: SCLK beats time, MOSI is the master talking. MISO is the slave answering, CS says when the exchange starts. The chip that beats time is the master, the one that follows is the slave. The master drives SCLK, MOSI and CS; the slave drives MISO. Only one bit sits on the wire at a time — a byte takes eight trips. 四根线各有一份活:SCLK 打拍子,MOSI 主机说话,MISO 从机回话,CS 喊开始。打拍子的那块叫主机,跟着的那块叫从机。SCLK、MOSI、CS 由主机驱动,MISO 由从机驱动。线上一次只有一位——一个字节要走 8 趟。

What are these four wires like? 这四根线像什么?

SPISPI the most common four-wire hookup between two chips. The wire that says start also names which chip — hence chip-select. 两块芯片之间最常见的四线接法。喊开始的那根还要点名是哪一块,所以叫片选。

It's like…就像……

One person taps a beat; the other listens only on the beat. Nobody agrees on speed beforehand — the tapper just stays under what the listener can follow. 一个人打拍子,另一个人只在拍子上听。两个人不用先商量快慢——只要别快过对方跟得上的速度。

7 打拍子那一头 the beat side 两块芯片那一头 the two-chip side 摇铃 ↔ 片选 the bell ↔ chip-select 拍子 ↔ 时钟线 beat ↔ clock wire 念的数字 ↔ 那一位 the number ↔ that one bit
Each piece above has a twin below. The bell is the chip-select, the beat is the clock wire, the number is the one bit. Left to right is the real order — the bell rings first. 打拍子那一头的每一样,芯片那一头都有对上的一样。摇铃是片选,拍子是时钟线,数字是数据线上的那一位。从左往右就是真实次序——先摇铃。

The clock is that beat 时钟就是那个拍子

模式 0(CPOL=0、CPHA=0)mode 0 (CPOL=0, CPHA=0) SPI's most used clock mode. The clock idles low. A bit is read on the rising edge (low to high) — a datasheet calls that moment the sample. The next bit appears on the falling edge. SPI 四种时钟模式里最常用的一种。时钟闲着是低的。上升沿(从低跳到高)读走一位,手册把这一下叫采样。下降沿(从高跳到低)换下一位。

The clock is one wire swinging between high and low; one swing is one beat. 时钟就是一根线在高低之间来回,来回一趟算一拍

SCLK SCLK high low 上升沿 the rising edge 1 MHz:一拍 1 微秒 1 MHz: one beat = 1 µs 2 MHz:一拍 0.5 微秒 2 MHz: one beat = 0.5 µs 时间 time
The clock idles low; in mode 0 a bit is read on the rising edge. 1 MHz is a million beats a second, so a beat is one microsecond — a blink fits 100,000. The lower trace is the same wire twice as fast: half the beat, twice as many. The master picks the rate; the slave's datasheet caps it. 时钟闲着是低的,模式 0 在上升沿读走一位。1 MHz 就是每秒一百万拍,所以一拍 1 微秒。眨一次眼,够打十万拍。下面一行是同一根线调快一倍:一拍缩到 0.5 微秒,同样一段时间里拍数翻倍。快慢由主机挑,上限写在从机的手册里。

One byte, eight beats 一个字节,8 拍走完

一位 / 一个字节one bit / one byte high or low only: a beat carries one 0 or 1 — a bit. Eight bits make a byte, top bit b7 first down to b0. 线上只有高低两档,一拍只送一个 0 或 1,这就是一位。8 位是一个字节,图上从最高位 b7 先走到 b0。
CS SCLK MOSI MISO 8 拍 = 8 微秒(1 MHz 时) eight beats = 8 µs at 1 MHz 采样点 sampled here b7 b0
Mode 0: the first bit is placed by the chip-select drop. Every later bit changes on a falling edge. MISO is the slave answering on the same eight windows. Only one sample point is circled; all eight sample. At 1 MHz a beat is 1 µs, so 8 bits take 8 µs. Sound moves 2.7 mm in that time. 模式 0:第一位在片选拉低时就摆好,之后每一位都在下降沿换。MISO 那一行是从机在同样 8 个窗口里回话。图上只圈了第一个采样点,8 个上升沿都在采。1 MHz 时一拍 1 微秒,8 位约走 8 微秒——声音只走约 2.7 毫米。

Why the data has to settle early 为什么数据要提前稳住

建立 / 保持时间setup / hold time how long the data must be steady before the sampling edge (setup). How long it must stay put after it (hold). 采样那一下之前,数据要先稳住多久(建立)。采完之后,还要再撑住多久(保持)。

The data must settle before the sampling edge, and hold still after it. 数据要在采样那一下之前就稳住,采完还得再撑一会儿。

SCLK MOSI 这一段就是一拍 this span is one beat 采样沿 the sampling edge 数据在这儿换 the data changes here 建立 setup 保持 hold
Not to scale: real parts want tens of nanoseconds, a few percent of a 1 µs beat. Miss either one and the sample lands on the previous bit. 箭头没有按比例画:真器件常是几十纳秒,只占 1 微秒一拍的百分之几。差一点,采到的就是上一位。

One transfer, three moments 一次传输,三个时刻

1

CS drops, first bit ready 片选拉低,摆好首位

2

Eight rising edges, a bit each 8 个上升沿各取一位

3

CS released, this one is over 片选放开,这次说完