hardware//I/O//serial bus

A serial bus is a set of wires over which chips exchange data one bit after another, and on a circuit board it is how a processor reads its sensors, converters and memories. Three of them sit on almost every embedded board, I2C, SPI and UART; between boxes the job passes to buses built for metres and electrical noise, such as CAN, RS-485 or EtherCAT, and to the analog 4-20 mA loop in a plant. All of them are chosen by the same five things: speed, distance, number of devices, robustness and, above all, determinism, whether a message always arrives within a bounded time.


A serial bus is a set of wires over which chips exchange data one bit after another, and on a circuit board it is how a processor reads its sensors, converters and memories. Three of them sit on almost every embedded board, I2C, SPI and UART; between boxes the job passes to buses built for metres and electrical noise, such as CAN, RS-485 or EtherCAT, and to the analog 4-20 mA loop in a plant. All of them are chosen by the same five things: speed, distance, number of devices, robustness and, above all, determinism, whether a message always arrives within a bounded time.

The choice starts with arithmetic. A periodic message iii of LiL_iLi​ bits sent every TiT_iTi​ seconds on a bus of RRR bits per second occupies a fraction of it, and the fractions add up to the bus utilization

U=∑iLiR Ti<1.U=\sum&#95;i \frac{L&#95;i}{R\,T&#95;i}<1 .U=i∑​RTi​Li​​<1.

As UUU approaches 1 the queues grow and latency climbs without bound. Reading the twelve bytes of an accelerometer and a gyroscope over I2C at 400 kHz, with address and register, costs about 15 bytes of 9 bits, some 340 µs: at 1 kHz that is a third of the bus, and at 8 kHz, with a period of 125 µs, it cannot be done. Over SPI at 10 MHz the same read takes about 10 µs.

Do the bus budget before choosing the part.

That one division is why the IMU of a flight controller hangs on SPI while the barometer and the magnetometer can share a slow I2C bus, and why the GNSS module gets a UART of its own.

I2C is two wires shared by many addressed chips, frugal in pins and slow: the bus for sensors read tens of times a second. SPI is a fast clocked link with one select line per chip, for whatever is read at kilohertz or streamed (an IMU, a fast converter, a flash memory). UART is a point-to-point link with no clock wire, the classic port for a GNSS receiver or a telemetry radio.

A bus fails in ways the software reads as data. A chip that hangs and holds a line, a frame lost to interference, or a driver that repeats the last value when a sensor stops answering all reach the estimator as numbers, and the last one looks like a perfectly steady process (sensor error model).

Every transfer also has a time cost that is not in the average: how the processor services the bus (DMA, interrupts) sets the jitter of each sample, which matters as much to a control loop as the bandwidth (real-time computing).