Every way two chips talk
UART, I²C, SPI, 1-Wire, a shift register, CAN, USB, or a protocol of your own on top. Distance, speed, wire count and how many devices share the bus decide which.
Most of the time the other chip decides: its datasheet names the bus. When you do get a choice, ask how many devices, how far, how fast, and how many pins you can spare.
- Two devices, point to point, often another board or a PC → UART: TX to RX, RX to TX, a shared ground, both ends set to the same baud rate in advance.
- Several slow peripherals on two wires (sensors, a small display, a real-time clock) → I²C: one shared open-drain bus with pull-ups, each device picked by its 7-bit address.
- A fast device (a display, an SD card, a fast ADC) → SPI: a clock, a data line each way, and one chip-select per device. Every transfer is a two-way swap.
- Many sensors on one data pin, slowly → 1-Wire (the DS18B20), each found by its ROM code; microsecond-timed, so it costs the sketch time.
- More plain digital inputs or outputs, not a conversation → a shift register (74HC595 out, 74HC165 in).
- Long cables, electrical noise, many nodes (vehicles, machines) → CAN, through a transceiver, terminated at both ends.
- Be a keyboard or a serial port to a computer → USB device mode, on a board whose chip has native USB.
Whatever the bus, your own messages on top of it need a frame: a start byte, a length, a version and a CRC.
Point to point
Section
UART
An 8N1 frame, least significant bit first, 10 bit times per byte; TX to RX with a shared ground.
Term
baud rate
Example
Term
8N1
A shared bus with addresses
Section
I²C
Two open-drain wires with pull-ups, a 7-bit address and a read/write bit, an acknowledge after every byte.
Term
I²C address
Example
Term
open-drain
A fast bus with chip-selects
Section
SPI
Clock, data out, data in, and a chip-select per device; the mode sets the clock's polarity and phase.
Term
chip select
Term
SPI mode
One wire, or none at all
Several DS18B20s on one pin with one pull-up, and the DHT22's pulse-width frame.
Section
Shift registers for more pins
Not a conversation, just more pins, with a 74HC595 for outputs and a 74HC165 for inputs.
Long cables and computers
Section
CAN bus fundamentals
A differential pair, 120 Ω at each end, and arbitration by identifier, where the losing frame is simply sent again.
Section
USB device mode
Presenting as a keyboard (HID) or a serial port (CDC) on a board with native USB.
Reading and designing the conversation
Section
Reading timing diagrams
Setup and hold against the clock edge, and decoding a byte from a UART, I²C or SPI trace.
Section
Designing a device protocol
A start byte, version, length, command, payload and CRC, parsed by a state machine that recovers from garbage.
Term