Why serial
A microcontroller is a small computer on one chip, and it often talks to sensor chips. Eight wires for a byte's eight bits would use many pins. A serial bus sends the bits one after another over a few wires.
UART
UART uses two data wires. The microcontroller's TX (transmit) pin goes to the sensor's RX (receive) pin, and RX goes to TX. There is no clock wire, so both sides first agree on a speed: the baud rate, such as 115200 bits per second.
To send the letter A (0x41), TX drops to 0 for a start bit, sends the eight data bits lowest bit first, then a 1 as the stop bit. At 115200 baud each bit lasts 8.68 µs, so the frame takes 86.8 µs.
I2C
I2C uses two wires shared by many chips: SDA carries data and SCL carries the clock. A chip can only pull a wire down to 0. Pull-up resistors pull it back up to 1 when nobody pulls. This is called open drain.
Each I2C chip has a 7-bit address. The microcontroller signals START, then sends 0x76, highest bit first, one bit per clock pulse on SCL. An eighth bit says write (0) or read (1). Every chip on the wires hears it.
Only the chip at 0x76 answers. On the ninth clock pulse it pulls SDA to 0: an ACK, short for acknowledge. At 100 kHz the byte and its ACK take nine pulses, 90 µs. Chip 0x3C stays silent.
SPI
SPI uses four wires: SCLK, the clock; MOSI, from microcontroller to sensor; MISO, from sensor to microcontroller; and CS, chip select. There are no addresses. To pick a chip, the microcontroller pulls that chip's own CS wire to 0.
With CS at 0, the clock ticks eight times and MOSI carries one bit per tick, highest bit first. Here the microcontroller sends 0xD0, the command that asks this sensor for its ID number.
SPI is full duplex: every tick moves one bit out on MOSI and one bit in on MISO at the same time. While a filler 0x00 goes out, the ID 0x60 comes back. At 10 MHz a byte takes only 0.8 µs.
Choosing a bus
UART links two devices, like a GPS module or a debug console. I2C links many slower chips with just two wires. SPI is the fastest but needs a CS wire per chip, so it suits displays, flash memory and SD cards.
The bits, one by one
;; step 1/10 · why-serial ;; about: Microcontroller, UART sensor, Sensor 0x76, SPI sensor parallel: 8 wires, 1 byte at once serial: 1 data wire, 8 bits in a row Three common serial buses: UART 2 wires TX, RX I2C 2 wires SDA, SCL (shared) SPI 4 wires SCLK, MOSI, MISO, CS bus: shared wires plus the rules for using them
The figure plays in slow motion. Real bits do not travel as little packets: the voltage on the whole wire changes almost at once, and the receiver reads it at the right moment. The sensor is modelled on the Bosch BME280, which speaks both I2C and SPI: its I2C address is 0x76 or 0x77, its ID register 0xD0 reads 0x60, and its SPI clock may run up to 10 MHz.