Skip to content
Book 1 cover: Digital Communication Foundations: Bits, Clocks, Codes and Errors
Book 1·FoundationsAvailable now

Digital Communication Foundations: Bits, Clocks, Codes and Errors

Bits, clocks, line codes, signal integrity, error control, framing and access — the ideas inside every protocol

The ideas inside every protocol, from the voltage on a wire to a decoded, error-checked message

974
pages
22
chapters
502
figures
71
labs

The scope of Book 1

From the series plan. Underlined names are Tier A protocols (several chapters), plain names Tier B (a full chapter), italic names Tier C (a compact section); bold labels group the topics.

  • Physical basics: logic levels and signalling families (TTL, LVCMOS, LVDS, CML, SSTL/POD); serial vs parallel and sync vs async; clocking and clock recovery (PLL and CDR basics)
  • Line codes: NRZ, NRZI, Manchester, 4b/5b, 8b/10b, 64b/66b, 128b/130b, scrambling, PAM3/PAM4
  • Signal quality: transmission lines, reflections and termination; signal integrity and eye diagrams
  • Errors: parity, checksums, CRC (worked by hand and in code), Hamming/SECDED, Reed–Solomon, BCH, an introduction to LDPC and polar codes, interleaving
  • Link rules: framing and bit stuffing; flow control (stop-and-wait, sliding window, credits); medium access and arbitration (polling, token, TDMA, CSMA/CD, CSMA/CA, bitwise arbitration); addressing; protocol state machines
  • Models and maths: the OSI and TCP/IP models; throughput, latency and efficiency maths
  • Data encodings inside protocols: TLV, ASN.1 (BER/DER/PER), CBOR, Protobuf, which you need to read 5G RRC messages, certificates, SNMP and Matter
  • Instruments: oscilloscope, logic analyzer, protocol analyzer, sigrok and Wireshark

Labs: CRC and 8b/10b in Python and Verilog; eye-diagram simulation; first logic-analyzer decode

Why this book, and how it is built

Every protocol in this series, from UART to 5G, is built from the same small set of ideas: a way to put bits on a wire, a way to keep sender and receiver in step, a code that makes the signal easy to receive, a check that catches errors, a frame that marks where a message starts and ends, and a rule for who may talk when. This book teaches those ideas once, completely, so that every later book can build on them.

You will compute CRCs by hand and in code, build a CRC circuit in Verilog, watch an eye diagram close as a cable gets longer, decode real captures with a logic analyzer and Wireshark, and finish by designing, building and debugging a small protocol of your own.

You will learn

  • Signals and logic levels
  • Clocks and sampling
  • Line codes
  • Transmission lines
  • Eye diagrams
  • CRC and error correction
  • Framing and flow control
  • Medium access
  • Encodings
  • Your protocol bench

Labs run on Python 3.13 (NumPy, SciPy, matplotlib, scapy), OSS CAD Suite 2026-11-12 (Icarus Verilog 14, Verilator 5, cocotb 2.1), sigrok-cli 0.7.2 and tshark 4.4.

5 parts, 22 chapters

Page counts are from the finished PDF. Open a chapter to see what you will be able to do after it.

Front matter: About This Book · Contents · List of Figures · List of Labs · How to Use This Book · Readiness Check · Learning Outcomes

PART 1

How Devices Talk

What a protocol is, how bits become voltages on a wire, and how sender and receiver stay in step.

  1. 1What a Protocol Is: Layers, Roles and the Protocol Passport34 pages · 7 learning outcomes · 2 labs

    Every book in this library teaches protocols: UART, I²C, CAN, USB, Ethernet, Wi-Fi, 5G and many more. Before we take any of them apart, we need to agree on what a protocol *is*, which questions every protocol must answer, and which words engineers use for the parts around it. This chapter gives you that common ground. You will follow one short message, "Hi!", from a program to the voltage on a wire; you will meet the running example of the whole book, a PC that reads an energy meter with Modbus; and you will learn the method this library uses to describe any protocol on one page, the **Protocol Passport**. In the lab you decode a real capture yourself.

    • Define a protocol, and give one rule of syntax, one of meaning and one of timing from a real protocol.
    • Draw the communication model (source, transmitter, channel, receiver, destination, noise) and map a real link onto it.
    • Tell a protocol from an interface, an electrical standard, a data format and an algorithm, using UART, RS-232, RS-485 and Modbus as examples.
    • List the questions every protocol answers, and answer them for UART and Modbus RTU.
    • Name the common roles (controller and target, host and device, client and server, peers) and read the "who drives the wire" colours of this library's timing diagrams.
    • Explain layers and encapsulation, and compare the OSI and TCP/IP models with a real stack.
    • Decode a capture with a protocol decoder, find the line settings from the samples, and fill in a Protocol Passport.
  2. 2Bits on a Wire: Logic Levels and Signalling Families36 pages · 7 learning outcomes · 4 labs

    In Chapter {ref:ch-what-is-a-protocol} you followed "Hi!" down to the wire, where a 1 was "a high voltage" and a 0 "a low voltage". This chapter asks the questions behind those words: how high is high, how much noise can a bit survive, and what kind of circuit puts it on the wire. The answers decide whether two chips can talk at all, why I²C needs pull-up resistors, why RS-485 and LVDS use two wires per signal, why DDR memory terminates its lines in a special way, and why a factory sensor sends its reading as a current. Part P4 of every protocol dossier, the physical layer, is built from them.

    • Read the input and output levels of a chip from its data sheet and compute the noise margins of a link.
    • Explain how TTL and CMOS inputs and outputs work, why logic moved from 5 V to 3.3 V and lower, and what HCT, LVCMOS, "5 V tolerant" and "absolute maximum" mean.
    • Choose between push-pull, open-drain and tri-state outputs, and explain wired-AND and bus contention.
    • Size a pull-up resistor from the rise time, the bus capacitance and the sink current, and explain why slow edges need Schmitt-trigger inputs.
    • Explain differential signalling, compare RS-485, LVDS and CML, and explain the reference-based SSTL and POD signalling of memory chips.
    • Explain current-loop signalling and work out a 4–20 mA loop budget.
    • Decide whether two devices can be connected directly, and choose a level-shifting method when they cannot.
  3. 3Serial and Parallel, Synchronous and Asynchronous33 pages · 7 learning outcomes · 2 labs

    In Chapter {ref:ch-logic-levels-and-signalling} you learned how one bit becomes a voltage on one wire. Real links send millions of bits, so two new questions appear. First, *which wires* carry the bits: many wires side by side, or one wire, bit after bit? Second, *how does the receiver know when* to look at each bit? Every protocol in this series gives its own answer to both questions, and those answers decide its speed, its pin count, its cable and the way you debug it. This chapter teaches the answers once, with real numbers, so that each later book can simply say "source-synchronous, half duplex" and you know exactly what that means.

    • Explain why serial links replaced parallel buses between chips and boxes, using skew, pin count, crosstalk and switching noise, with numbers.
    • Compute a skew budget for a parallel bus and the highest clock rate it allows.
    • Tell simplex, half-duplex and full-duplex links apart and compute the cost of turnaround.
    • Describe the four ways a receiver knows when to sample: common clock, source-synchronous, embedded clock and asynchronous.
    • Compute the timing budget of a common-clock link and compare it with a source-synchronous one.
    • Explain start-stop framing and the asynchronous handshake, and say where each is used.
    • Place the protocols of this series on a map of serial/parallel and timing schemes, and choose a scheme for a new link.
  4. 4Clocks, Sampling and Clock Recovery38 pages · 7 learning outcomes · 3 labs

    Chapter {ref:ch-serial-parallel-sync-async} showed four ways a receiver can know *when* to look at each bit: a common clock, a forwarded clock, a clock hidden in the data, or its own clock re-aligned on every start bit. This chapter does the timing work behind all four. You will learn how fast a link really signals, where in each bit a receiver should look, how good real clocks are, how much clock error a UART can survive, how a phase-locked loop makes a fast clock from a slow one, how a receiver rebuilds a clock from the data alone, and how engineers measure the wobble called jitter. Every later book uses these numbers: the baud error of a UART, the ±500 ppm of USB, the spread-spectrum clock of PCI Express and the jitter limits of every fast serial link.

    • Tell symbol rate, line bit rate and data rate apart, and compute each for real links such as a UART, USB, PCI Express and Ethernet.
    • Explain where and how often a receiver samples, what oversampling buys, and why a synchronizer is needed against metastability.
    • Work with clock accuracy in ppm: drift between two clocks, a crystal's error budget, elastic buffers and spread-spectrum clocking.
    • Derive the baud-rate tolerance of an asynchronous receiver for any frame format and oversampling ratio, and choose a baud-rate divisor.
    • Describe how a PLL multiplies a clock, and how its loop bandwidth sets the lock time and which jitter passes.
    • Explain how a CDR recovers a clock with a bang-bang phase detector and a phase interpolator, and what its proportional and integral paths do.
    • Measure and budget jitter: TIE, period and cycle-to-cycle jitter, random and deterministic jitter, and total jitter at a target bit error ratio.
PART 2

Line Codes and Signal Quality

How bits are shaped into signals that travel well, what a real wire does to them, and how to judge the result with an eye diagram.

  1. 5Line Codes I: NRZ, NRZI, RZ, Manchester and AMI44 pages · 7 learning outcomes · 4 labs

    Chapter {ref:ch-clocks-sampling-recovery} showed that a receiver can only keep its clock in step if the data gives it transitions, and that a run of equal bits leaves it guessing. This chapter is about the rule that decides what the wire actually carries for each bit: the **line code**. You will meet the five classic families, NRZ, NRZI, RZ, Manchester and AMI, and learn to judge any code by six questions: does it give enough edges, does it keep the average level at zero, how much bandwidth does it need, does it survive swapped wires, can it detect errors, and what does it cost? Every later book uses these codes: UART and CAN send NRZ, USB 2.0 sends NRZI with bit stuffing, 10 Mbit/s Ethernet and DALI lighting send Manchester, digital audio sends biphase mark, and telephone trunks send AMI with HDB3 or B8ZS. Chapter {ref:ch-block-codes-scrambling-pam} then adds what fast links need: block codes and scramblers, which give edges and DC balance with far less overhead, and multi-level (PAM) signals, which send more than one bit per symbol.

    • Explain what a line code is, and judge any code by its transitions, DC balance (running digital sum), bandwidth, polarity sensitivity, error detection and cost.
    • Encode and decode bits by hand in NRZ, NRZI, MLT-3, RZ, Manchester (both conventions), differential Manchester, biphase mark and AMI.
    • Explain USB 2.0's NRZI with bit stuffing, count stuff bits, and compute the clock drift that stuffing allows.
    • Explain how AMI detects errors and how B8ZS and HDB3 fill long runs of zeros, and encode HDB3 by hand.
    • Read the power spectrum of a line code, find its first null and its highest fundamental, and work out the bandwidth a link needs.
    • Explain AC coupling and baseline wander, and compute the droop of a run of equal bits through an RC coupling network.
    • Choose a basic line code for a link, and debug the common faults: wrong convention, swapped wires, missing bit stuffing and mismatched line codes.
  2. 6Line Codes II: Block Codes, Scrambling and PAM56 pages · 7 learning outcomes · 5 labs

    Chapter {ref:ch-line-codes-basic} taught the basic line codes, and showed that each one fixes one problem by paying for it somewhere else. NRZ is narrow but goes flat in long runs; Manchester gives an edge in every bit but needs twice the bandwidth. A link that runs at gigabits per second needs edges and DC balance even more than a slow one, yet it cannot pay Manchester's price. This chapter teaches the three tools that fast serial links use instead: **block codes** (4b/5b, 8b/10b, 64b/66b, 128b/130b), **scramblers**, and **multi-level signals** (PAM3 and PAM4). You will meet them in Ethernet, PCI Express, USB, SATA, DisplayPort and the JESD204 links of data converters, so this chapter is the key to every high-speed book of the series.

    • Explain what a block code is, compute its efficiency and overhead, and encode data with 4b/5b as Fast Ethernet sends it.
    • Encode bytes and control characters in 8b/10b by hand, tracking the running disparity, and explain its run length, DC balance and the A7 rule.
    • Explain commas, word alignment, ordered sets and 8b/10b error detection, and the logic that does them in hardware.
    • Explain frame-synchronous and self-synchronizing scramblers, and predict how each one synchronizes and what one line error does to the data.
    • Describe 64b/66b and 128b/130b blocks, their sync headers and block lock, and estimate lock time and the chance of a false lock.
    • Compute the symbol rate, line rate and data rate of a link for any block code and any number of signal levels.
    • Explain PAM4 and PAM3, Gray coding and the eye-height cost, and choose and debug a coded link.
  3. 7Wires Are Not Ideal: Transmission Lines and Termination38 pages · 6 learning outcomes · 3 labs

    In Chapters {ref:ch-line-codes-basic} and {ref:ch-block-codes-scrambling-pam} you shaped bits into signals that travel well. Until now, a wire was a perfect connection: what the driver put in at one end appeared at once, unchanged, at the other end. Real wires are not like that. A voltage change needs time to travel, and when it reaches the end of a wire it can bounce back, like an echo. On a fast board, a 15 cm trace can turn a clean 3.3 V edge into a signal that jumps to 5.5 V and rings for many nanoseconds. This chapter explains why, and how engineers stop it. You will learn why CAN and RS-485 cables have a 120 Ω resistor at each end, why USB pairs are 90 Ω, why a small resistor sits next to a fast clock driver, and how a cable tester finds a broken wire metres away.

    • Compute propagation delay, velocity factor and electrical length, and use the critical-length rule to decide when a wire must be treated as a transmission line.
    • Explain characteristic impedance with the L–C model, and estimate the impedance of coax, wire pairs, microstrip and stripline from their geometry.
    • Compute reflection coefficients, return loss and VSWR, and predict the waveform on any resistively terminated line with a bounce diagram.
    • Choose and size series, parallel, Thévenin, VTT, AC and differential terminations, and compute the power each one costs.
    • Name the impedance and termination of real cables and interfaces: Ethernet, CAN, RS-485, USB, LVDS and coax.
    • Find reflections on a bench with an oscilloscope and a time-domain reflectometer, and read distance and impedance from the echoes.
  4. 8Signal Integrity, Noise and the Eye Diagram43 pages · 7 learning outcomes · 4 labs

    In Chapter {ref:ch-transmission-lines} you learned that a fast wire is a transmission line and that every impedance change sends back an echo. That chapter treated the line as lossless. Real lines are not: copper and insulation absorb energy, and they absorb more of it the faster the signal changes. Neighbouring wires leak into each other, and the ground inside a chip moves when many outputs switch. In Lab {lab:lab-8-1}, a 10 Gbit/s signal that leaves the transmitter as clean steps arrives after 0.8 m of ordinary circuit board with its fastest content cut to one tenth, and no bit can be read reliably any more. This chapter explains each kind of damage, shows you how engineers see it all at once in an **eye diagram**, how they put a number on it (the bit error ratio, the Q-factor and the bathtub curve), how receivers undo part of it with equalizers, and how the same fast edges cause electromagnetic emissions.

    • Explain why a long trace acts as a low-pass filter, and compute skin depth, conductor and dielectric loss and the loss at the Nyquist frequency.
    • Read inter-symbol interference from a pulse response, and estimate the worst-case eye height from its cursors.
    • Build and read an eye diagram (height, width, crossing, jitter, mask) and use its shape to tell loss, reflections, crosstalk and noise apart.
    • Convert between Q-factor and bit error ratio, plan a BER test, and read total jitter and eye width from a bathtub curve.
    • Compute near-end and far-end crosstalk and ground bounce, and choose the layout changes that reduce them.
    • Explain how FFE, CTLE and DFE equalizers reopen a closed eye, and what each one cannot do.
    • Explain where emissions come from, compute the common-mode current that fails an emission limit, and name the board habits that keep a product quiet.
PART 3

Making Links Reliable

How receivers detect and correct errors — from parity to CRCs and error-correcting codes — find where a message starts, and ask for what was lost.

  1. 9Errors, Parity and Checksums39 pages · 7 learning outcomes · 4 labs

    Part 2 of this book was about signals: how bits travel on real wires, and how noise, reflections and jitter close the eye until the receiver samples a wrong bit. This chapter starts Part 3, where the question changes from "how do we send a bit well?" to "what do we do when a bit arrives wrong anyway?". The first answer is to *notice*. You will learn what kinds of errors real links make, how to predict how often a frame is hit, and the simplest checks that catch them: parity bits, the LRC, the Internet checksum, and the Fletcher and Adler checksums. You will also learn, with numbers from real tests, exactly which errors each check misses. The next two chapters build on that list to explain why almost every link uses a CRC.

    • Name the main types of transmission error (single-bit, multi-bit, burst, erasure, slip) and give a physical cause of each.
    • Use the BER and the binomial distribution to compute the chance of 0, 1, 2 or more errors in a frame, the frame error rate, and the test time needed to prove a BER.
    • Compute even and odd parity, use 2-D parity to locate and correct a single error, and state which error patterns parity misses.
    • Compute a Modbus ASCII LRC and an XOR LRC, and explain how they differ.
    • Compute and check the Internet checksum of an IPv4 header with one's complement arithmetic.
    • Compute Fletcher and Adler-32 checksums and explain why their second sum catches reordering.
    • Predict which error patterns each check misses, and choose a check for a design.
  2. 10Cyclic Redundancy Checks (CRC) from First Principles23 pages · 5 learning outcomes · 3 labs

    In Chapter {ref:ch-parity-checksums} you met parity bits and checksums. They are cheap, but they miss whole families of errors: two flipped bits, swapped bytes, changes that cancel in a sum. This chapter teaches the check that almost every link in this series uses instead: the **cyclic redundancy check**, or CRC. Your Ethernet card, every CAN node in a car, every USB packet, every Modbus meter and every zip file computes one. Here you learn how a CRC works from first principles: you compute CRCs by hand, prove which errors they always catch, and build the circuit in Verilog. Chapter {ref:ch-crc-in-practice} then turns to practice: the exact CRCs that real protocols use, fast software, real frames and debugging.

    • Explain why a CRC catches error patterns that parity and checksums miss.
    • Compute a CRC by hand with modulo-2 long division, and check a received codeword.
    • Explain which errors a CRC always detects (single, double, odd counts, bursts up to r bits), and what the Hamming distance of a CRC is and why it depends on the message length.
    • Draw the shift-register (LFSR) circuit of a CRC, trace it clock by clock, and describe it in Verilog.
    • Explain how hardware computes a CRC several bits per clock, and estimate how many clock cycles a CRC unit needs for a frame.
  3. 11CRCs in Practice: Parameters, Software and Real Protocols26 pages · 6 learning outcomes · 2 labs

    In Chapter {ref:ch-crc} you learned how a CRC works: a remainder of polynomial division, computed by hand or by a shift register, that catches every burst up to its width. This chapter is about CRCs as an engineer meets them. Real CRCs add a start value, a bit order and a final XOR to the division, and a protocol must also say which bits the CRC covers and in which order it is sent. You will describe any CRC with seven numbers, write fast software, check the CRCs of real Ethernet, CAN, USB and Modbus frames with real tools, use the residue, choose a polynomial for a new design, and debug the mismatches that every engineer meets sooner or later.

    • Describe any CRC completely with the parameter model (width, poly, init, refin, refout, xorout, check, residue), and identify a CRC from its check value.
    • Implement bitwise and table-driven CRCs in software, choose between them, and prove them with check values.
    • Find what the CRC covers and in which order it is sent in Ethernet, CAN, CAN FD, USB, Modbus RTU, SMBus, 1-Wire and SD frames, and verify real frames with tools.
    • Use the residue to check a frame without comparing CRCs.
    • Choose a CRC for a new protocol from its Hamming distance at the frame length, and explain the CAN FD fix and why a CRC is not a security check.
    • Debug a CRC mismatch step by step.
  4. 12Error-Correcting Codes36 pages · 7 learning outcomes · 4 labs

    Chapters {ref:ch-parity-checksums} to {ref:ch-crc-in-practice} taught checks that *detect* errors. When such a check fails, the receiver throws the frame away and asks for it again, as Chapter {ref:ch-ack-retransmission-flow} will show. Often that is impossible or too slow: a space probe is minutes away, a TV transmitter cannot hear its viewers, and a memory chip holds the only copy of your data. This chapter teaches codes that let the receiver *repair* errors by itself. You will correct Hamming codes by hand, build the SECDED code of ECC memory in Verilog, decode a Reed–Solomon codeword step by step, run a Viterbi decoder, measure how many decibels a code saves, and see where LDPC and polar codes fit in Wi-Fi and 5G.

    • Explain forward error correction, say when a receiver cannot ask for data again, and use the minimum distance to find how many errors and erasures a code detects and corrects.
    • Encode and decode a Hamming(7,4) codeword by hand with the syndrome, and explain why two errors cause a miscorrection.
    • Explain SECDED and the (72,64) code of ECC memory, decode its four cases, and describe the circuit in Verilog.
    • Explain how Reed–Solomon codes use symbols to correct bursts and erasures, follow a Reed–Solomon and a BCH decode step by step, and size a code for a burst.
    • Encode with a convolutional code, decode it with the Viterbi algorithm on a trellis, and compare hard and soft decisions.
    • Compute the code rate and the energy per channel bit, read coding gain from BER curves, and use interleaving against bursts.
    • Describe turbo, LDPC and polar codes at idea level, and choose FEC, ARQ or hybrid ARQ for a link.
  5. 13Framing: How a Receiver Finds the Message42 pages · 6 learning outcomes · 4 labs

    The last four chapters gave the receiver a way to check a message: parity, checksums, CRCs and error-correcting codes. Every one of them assumes something we have not yet earned: that the receiver knows *where the message starts and ends*. A CRC over the wrong 50 bytes is useless. On a wire there are no gaps between messages unless the protocol makes them. Bits and bytes arrive as one long stream, and the receiver must cut it into **frames**. This chapter teaches every way real protocols do that: silence, length fields, sync words, flags with bit or byte stuffing, COBS, special line-code symbols and self-checking headers. You will stuff bits in Verilog, decode a SLIP capture, measure the overhead of each method and watch four framers recover from damage.

    • Explain why a receiver needs frame synchronisation, and list what a good framing method must provide.
    • Frame messages by silence, break and length fields, compute the Modbus RTU and LIN timings, and protect a length field.
    • Use preambles and sync words, compute how often a sync pattern appears by chance, and explain how a receiver confirms lock.
    • Apply HDLC bit stuffing by hand and in Verilog, and compare it with the stuffing rules of CAN and USB.
    • Encode and decode SLIP, PPP and COBS frames, and compute their average and worst-case overhead.
    • Choose a framing method for a new link from its overhead, its worst case and how fast it recovers after an error.
  6. 14Acknowledgement, Retransmission and Flow Control44 pages · 6 learning outcomes · 3 labs

    Chapters {ref:ch-parity-checksums} to {ref:ch-crc-in-practice} taught a receiver to *detect* a damaged frame, Chapter {ref:ch-error-correcting-codes} taught it to *repair* some damage, and Chapter {ref:ch-framing} taught it to find where each frame starts. One problem is left: what happens to a frame that is thrown away, or never arrives? And what stops a fast sender from flooding a slow receiver? This chapter answers both. You will learn how acknowledgements, timers and sequence numbers make a link reliable, compare the three classic retransmission schemes with their exact efficiency formulas, and then learn the flow-control methods, from two UART wires to the credits of PCI Express and the ready/valid handshake inside every chip. Every formula is checked against a simulation you can run.

    • Explain how acknowledgements, timers and sequence numbers recover lost frames, lost acknowledgements and duplicates.
    • Compute the utilisation of stop-and-wait and the bandwidth-delay product of a link, and size a window for full speed.
    • Trace go-back-N and selective repeat, and choose the number of sequence-number bits from the window-size rules.
    • Compute the throughput of the three ARQ schemes on a lossy link, and set a retransmission timeout from measured round-trip times.
    • Design on/off, window and credit-based flow control, and size the buffers and thresholds they need.
    • Describe the ready/valid handshake and back-pressure in hardware, and explain why a skid buffer is used.
PART 4

Sharing the Medium and Building Stacks

Who talks, when, and to whom; how protocols are described; and how layers stack into a complete system.

  1. 15Topologies, Addressing and Roles32 pages · 6 learning outcomes · 2 labs

    So far most of this book has looked at one sender and one receiver: how the bits travel (Chapters {ref:ch-logic-levels-and-signalling} to {ref:ch-signal-integrity-eye}), how errors are caught and repaired (Chapters {ref:ch-parity-checksums} to {ref:ch-error-correcting-codes}), and how frames are found and acknowledged (Chapters {ref:ch-framing} and {ref:ch-ack-retransmission-flow}). Real systems connect many devices. A car has dozens of controllers on a few buses, a sensor board has a handful of chips on two wires, and a data centre has thousands of servers behind switches. This chapter answers three questions that every such system must settle: how the devices are wired (the topology), how a message names the device it is for (the address), and who may start a conversation (the roles). Chapter {ref:ch-medium-access-arbitration} then answers the fourth: what happens when two devices start at once.

    • Describe the basic topologies (point-to-point, bus, star, ring, mesh, daisy chain, tree), tell physical from logical topology, and name a real protocol for each.
    • Explain what each topology does to the signal, and work out how many nodes a bus can carry from its capacitance, unit-load or stub limits.
    • Compare topologies by cabling, single points of failure and fault tolerance.
    • Name the roles of the main protocols and say who starts a transaction and who drives the wire.
    • Size an address field, and choose and explain fixed, configured and dynamic addressing, including USB enumeration, I3C dynamic addresses and DHCP.
    • Use unicast, multicast and broadcast addresses, map multicast groups to MAC addresses, and compute and prevent address collisions.
  2. 16Medium Access and Arbitration39 pages · 7 learning outcomes · 2 labs

    In Chapter {ref:ch-topologies-addressing-roles} you saw how devices are wired together and how they name each other. A bus, a ring or a radio channel is one **shared medium**: when two devices send at the same moment, their signals add up on the wire and the receiver gets nonsense. This chapter teaches the rules that decide who may send when. Some protocols take turns (polling, a token, time slots), some let everyone try and repair the damage (ALOHA, Ethernet, Wi-Fi), and some, like CAN and I²C, let everyone start and decide the winner bit by bit without losing a single bit time. You will derive the famous 18.4 % and 36.8 % limits of ALOHA, find the minimum Ethernet frame from the speed of light, build bitwise arbitration in Verilog, and see why strict priority can starve a message.

    • Explain why a shared medium needs an access rule, and sort access methods into taking turns, random access and arbitration.
    • Compute polling cycles, token waiting times and TDMA slot budgets.
    • Derive the throughput of pure and slotted ALOHA, and explain how carrier sense and the ratio a = τ/T change it.
    • Explain CSMA/CD, compute the minimum frame length from the round-trip time, and describe binary exponential back-off and its capture effect.
    • Describe CSMA/CA in Wi-Fi: DIFS, the back-off countdown, the ACK, RTS/CTS and the NAV.
    • Explain bitwise arbitration on a wired-AND bus in CAN and I²C, predict the winner and where each loser drops out, and describe the logic in Verilog.
    • Judge priority, fairness and starvation, and choose an access method for a design.
  3. 17State Machines, Timing Diagrams and Reading a Specification35 pages · 7 learning outcomes · 3 labs

    Every protocol in this series is written down twice: once as rules about *what happens next* (send this, wait for that, give up after so long) and once as rules about *time* (this edge must come at least so many nanoseconds after that one). Engineers draw the first kind as **state machines** and sequence charts, and the second kind as **timing diagrams** and timing tables. Both live inside a **specification**, a document with its own strict language. This chapter teaches you to read and write all three. You will build a small request/response protocol with a timeout and retries in Python and in Verilog and prove that both behave the same, check a real I²C capture against the specification's timing table, and watch the TCP state machine inside the Linux kernel.

    • Describe one side of a protocol as a finite-state machine with states, events, actions and guards, and write its complete state table.
    • Tell Mealy machines from Moore machines, and choose between them in hardware.
    • Model timeouts, retries and back-off as states, choose a timeout from a timing budget, and compute the time to give up.
    • Read and draw message-sequence charts, and relate them to state machines.
    • Build a protocol state machine in Verilog and verify it against a reference model with a self-checking testbench, transition coverage and a traceability matrix.
    • Read timing diagrams and datasheet timing tables (reference edges and levels, min, typ, max, conditions), and check a capture against a table.
    • Read a specification: normative words, normative and informative text, errata, conformance.
  4. 18Layered Stacks: OSI and TCP/IP in Practice31 pages · 6 learning outcomes · 3 labs

    Chapter {ref:ch-what-is-a-protocol} gave you a first look at layers: the OSI and TCP/IP models, the word *encapsulation*, and one Modbus request carried by two different stacks. Since then you have studied the jobs that layers do one at a time: line codes, error checks, framing, retransmission, addressing and medium access. This chapter puts those jobs back together. You will build a real stacked packet and take it apart with Wireshark's dissector, count what every header costs, cut a message that is too big into pieces, and map the stacks of the later books (UART, CAN, Ethernet, USB, Wi-Fi and 5G) onto the layer models. After this chapter, a capture of any protocol will look to you like a set of nested envelopes that you know how to open.

    • Explain encapsulation with headers and trailers, use the words SDU, PCI and PDU, and name the PDU of each layer (bit, frame, packet, segment, message).
    • Compare the OSI and TCP/IP models layer by layer, say which network devices work at which layer, and explain why real stacks do not map cleanly onto either.
    • Describe service interfaces, service primitives and service access points, and follow the demultiplexing fields (EtherType, protocol number, port) through a real frame.
    • Compute the header overhead and efficiency of a real stack for a given payload, and name ways to reduce it.
    • Explain MTU and fragmentation, work out the fragments of a large IPv4 datagram, and explain why stacks avoid fragmentation (path MTU discovery, MSS, IPv6 rules, ISO-TP segmentation).
    • Recognise cross-layer shortcuts and map UART + Modbus, CAN + ISO-TP + UDS, Ethernet + IP + TCP + HTTP, USB, Wi-Fi and 5G onto layers.
  5. 19Data Encodings Inside Protocols30 pages · 6 learning outcomes · 3 labs

    Chapter {ref:ch-layered-stacks} opened the envelopes of a stack one by one. This chapter looks at what is written *inside* them. A header field, a sensor reading or a certificate is a value, and every protocol needs a rule that turns values into bytes and bytes back into values. Some protocols use fixed layouts, where the position of a byte gives its meaning; others put a tag or a key in front of every value. You will learn byte order and bit order, the source of countless "the number is wrong" bugs; alignment and padding; and the encodings you will meet again in the later books: TLV, ASN.1 with BER, DER and PER, CBOR, Protocol Buffers and JSON. In the labs you encode one record seven ways, read a real certificate and an SNMP message byte by byte, and build a 5G radio message bit by bit.

    • Explain big-endian, little-endian and network byte order, and convert multi-byte values correctly in code.
    • Tell bit order on the wire from bit numbering in a document, and read a field defined with IETF, C or ITU-T bit numbers.
    • Explain alignment and padding, and why protocol code must not cast a byte buffer to a struct.
    • Encode and decode TLV, ASN.1 BER/DER and PER, CBOR and Protocol Buffers values at byte level.
    • Read real BER and DER messages (SNMP, an X.509 certificate) and a PER message (5G RRC) field by field.
    • Compare encodings by size, parsing cost, schema and extensibility, and choose one for a design.
PART 5

Measuring and Building

The maths of throughput and latency, the instruments of a protocol engineer, and a complete protocol built and debugged end to end.

  1. 20Performance Maths: Bandwidth, Throughput, Efficiency and Latency36 pages · 7 learning outcomes · 3 labs

    Every chapter so far has added something to a link: a line code, a frame, a CRC, stuff bits, an acknowledgement, a turn to talk. Each of these costs time on the wire. This chapter puts numbers on those costs. You will learn to say exactly how much useful data a UART, a CAN bus, an Ethernet port and a USB link can carry, where the time goes between "send" and "received", why a fast link can still be slow over a long distance, why delay explodes as a link gets busy, and what the hard limits of Nyquist and Shannon allow. These are the numbers that decide whether a design meets its requirements, and the first numbers an interviewer or a design review will ask for.

    • Tell bandwidth, line rate, throughput and goodput apart, and walk from a link's symbol rate down to its goodput.
    • Compute the frame efficiency of UART, classical CAN (with worst-case bit stuffing), Ethernet and USB full-speed transfers, and the throughput each allows.
    • Split a latency into processing, queueing, serialisation and propagation delay, and build a worst-case latency budget.
    • Use the bandwidth-delay product and utilisation to explain why request–response and windowed protocols run below the line rate.
    • Predict how queueing delay grows with load with the M/M/1 and M/D/1 formulas and Little's law, and explain what a priority queue changes.
    • Compute the Nyquist and Shannon limits of a channel and explain what they promise.
    • Find why a link is slower than expected, by computing its best case and measuring the line.
  2. 21Your Protocol Bench: Scopes, Logic Analyzers and Packet Tools32 pages · 6 learning outcomes · 3 labs

    Every chapter of this book has shown you a capture: a UART byte in Chapter {ref:ch-what-is-a-protocol}, an eye diagram in Chapter {ref:ch-signal-integrity-eye}, a CAN frame and an Ethernet FCS in Chapter {ref:ch-crc-in-practice}. This chapter is about the instruments that make those captures, and about using them without fooling yourself. You will learn what an oscilloscope, a logic analyzer, a protocol analyzer and Wireshark each see; how bandwidth, sample rate, probes and thresholds change what they show; how to capture, decode and explain UART, SPI and I²C traffic with sigrok; and how to find the one bad packet in a capture with Wireshark's filters. Every later book uses these tools.

    • Explain what an oscilloscope, a logic analyzer, a protocol analyzer and a packet-capture tool each see, and choose the right one for a symptom.
    • Choose an oscilloscope's bandwidth, sample rate and memory depth, and predict the rise time and the aliases it will show.
    • Use probes correctly: compensation, short grounds, differential probes and safety.
    • Set a logic analyzer's sample rate, threshold and mode, and recognise what sampling too slowly does.
    • Capture, decode and explain UART, SPI and I²C traffic with sigrok, and read a VCD file.
    • Capture and filter packets with Wireshark and tshark: capture and display filters, follow stream, expert information, pcap and pcapng.
  3. 22Project: Build and Debug a Tiny Protocol41 pages · 6 learning outcomes · 5 labs

    You have now met every idea a link protocol is made of: bits on a wire, sampling, a CRC, framing, acknowledgements and timers, state machines and efficiency. In this last chapter you put them together. You will write the specification of a small framed serial protocol called **TinyLink**, build it twice (in Python and, for the receiver, in Verilog), capture it as a waveform and decode it with real tools, break it on purpose and watch it recover, measure its throughput against the formulas of earlier chapters, and find three real bugs the way engineers find them. Every number in the chapter comes from the five labs in `labs/01/ch22`.

    • Write a complete specification for a small framed serial protocol: frame format, CRC parameters, byte stuffing, ACK/NACK rules, timeouts and state machines.
    • Implement the protocol in Python, and show it recovering from bit errors, lost frames, lost ACKs, duplicates and late replies.
    • Build the receiver's UART, deframer and CRC check in Verilog, and verify it against a golden model with a self-checking testbench.
    • Capture a link as a waveform and decode it with sigrok and a protocol decoder of your own.
    • Compute and measure the efficiency of a stop-and-wait link against the bit error ratio and the payload length, and explain where the formulas and the measurements differ.
    • Find wrong CRC parameters, a wrong byte order and a missing escape with the tools.

Appendix A

Final Test

23 pages

Appendix B

Answers

57 pages

Appendix C

Revision Cards

12 pages

Appendix D

Glossary

30 pages

Every lab in the book, run on free tools

Desk labs run on a laptop; their printed output comes from real runs.

Chapter 1

What a Protocol Is: Layers, Roles and the Protocol Passport

  • 1.1Decode a ready-made capture
  • 1.2One Modbus request, two stacks

Chapter 2

Bits on a Wire: Logic Levels and Signalling Families

  • 2.1Noise margins from real data sheets
  • 2.2Wired-AND and contention in Verilog
  • 2.3Pull-ups and rise times without SPICE
  • 2.4Differential, memory and current-loop signalling

Chapter 3

Serial and Parallel, Synchronous and Asynchronous

  • 3.1The skew budget
  • 3.2Parallel against serial in Verilog

Chapter 4

Clocks, Sampling and Clock Recovery

  • 4.1Clock maths
  • 4.2The baud-mismatch simulator
  • 4.3PLL, CDR and jitter

Chapter 5

Line Codes I: NRZ, NRZI, RZ, Manchester and AMI

  • 5.1Line codes by program
  • 5.2Spectra, bandwidth and baseline wander
  • 5.3Manchester in hardware
  • 5.4USB NRZI and bit stuffing in hardware

Chapter 6

Line Codes II: Block Codes, Scrambling and PAM

  • 6.18b/10b and 4b/5b by program
  • 6.28b/10b in Verilog
  • 6.3Scramblers: synchronization, errors and the killer packet
  • 6.464b/66b blocks and block lock
  • 6.5PAM4 against NRZ

Chapter 7

Wires Are Not Ideal: Transmission Lines and Termination

  • 7.1Transmission-line maths
  • 7.2Bounce diagrams and a line simulator
  • 7.3Termination compared

Chapter 8

Signal Integrity, Noise and the Eye Diagram

  • 8.1Eye diagrams of a channel that gets longer
  • 8.2BER, Q-factor and bathtub curves
  • 8.3Equalizers that reopen a closed eye
  • 8.4Crosstalk, ground bounce and EMC

Chapter 9

Errors, Parity and Checksums

  • 9.1The maths of bit errors
  • 9.2Parity, 2-D parity and the LRC on a UART line
  • 9.3The Internet checksum, by hand and by tshark
  • 9.4The checksum zoo and the error-injection test

Chapter 10

Cyclic Redundancy Checks (CRC) from First Principles

  • 10.1CRC by hand, by program
  • 10.2Hamming distance by search
  • 10.3The CRC as a circuit

Chapter 11

CRCs in Practice: Parameters, Software and Real Protocols

  • 11.1One engine for every CRC
  • 11.2CRCs in real frames

Chapter 12

Error-Correcting Codes

  • 12.1Hamming codes by program
  • 12.2SECDED (72,64) in Verilog
  • 12.3Reed–Solomon and BCH codes at work
  • 12.4Convolutional codes, Viterbi and BER curves

Chapter 13

Framing: How a Receiver Finds the Message

  • 13.1HDLC bit stuffing in Python and Verilog
  • 13.2SLIP on the wire
  • 13.3COBS and the overhead of every stuffing method
  • 13.4A framer that recovers

Chapter 14

Acknowledgement, Retransmission and Flow Control

  • 14.1An ARQ simulator with loss and delay
  • 14.2Credits and XON/XOFF
  • 14.3A ready/valid handshake in Verilog

Chapter 15

Topologies, Addressing and Roles

  • 15.1Topologies and their failures
  • 15.2Address assignment, static and dynamic

Chapter 16

Medium Access and Arbitration

  • 16.1Random access in numbers
  • 16.2Bitwise arbitration in Verilog

Chapter 17

State Machines, Timing Diagrams and Reading a Specification

  • 17.1A handshake with timeout and retry
  • 17.2Checking timing against a table
  • 17.3The TCP state machine in the Linux kernel

Chapter 18

Layered Stacks: OSI and TCP/IP in Practice

  • 18.1A stacked packet with scapy and tshark
  • 18.2Overhead of six stacks
  • 18.3Fragmentation and reassembly

Chapter 19

Data Encodings Inside Protocols

  • 19.1Byte order and bit order
  • 19.2ASN.1 by hand
  • 19.3One record, seven encodings

Chapter 20

Performance Maths: Bandwidth, Throughput, Efficiency and Latency

  • 20.1Frame efficiency of four links
  • 20.2Latency, budgets and the bandwidth-delay product
  • 20.3Delay against load

Chapter 21

Your Protocol Bench: Scopes, Logic Analyzers and Packet Tools

  • 21.1The instrument’s own maths
  • 21.2Capture, decode, explain
  • 21.3Wireshark from the command line

Chapter 22

Project: Build and Debug a Tiny Protocol

  • 22.1TinyLink in Python
  • 22.2The TinyLink receiver in Verilog
  • 22.3Capture and decode TinyLink
  • 22.4TinyLink throughput
  • 22.5Three bugs and how the tools find them

Real pages from the PDF

Tap a page to see it full size. These are the pages exactly as you get them.

Protocols this book teaches

From the series register. This book is each one's home: the place it is taught in full. Other books only use it.

ProtocolDepthGoverning spec
CRCCyclic Redundancy CheckTier Adefined per protocol (e.g. IEEE 802.3 CRC-32, ISO 11898-1 CRC-15)
128b/130b128B/130B block codeTier BPCI Express Base Specification 3.0+
4b/5b4B/5B block codeTier BIEEE 802.3 clause 24; ISO 9314 (FDDI)
64b/66b64B/66B block codeTier BIEEE 802.3 clause 49
8b/10b8B/10B block code (Widmer–Franaszek)Tier BIEEE 802.3 clause 36; Widmer & Franaszek (1983)
ASN.1Abstract Syntax Notation One (BER/DER/PER encodings)Tier BITU-T X.680–X.683, X.690 (BER/DER), X.691 (PER)
BCH codeBose–Chaudhuri–Hocquenghem codeTier Btextbook technique
CBORConcise Binary Object RepresentationTier BRFC 8949
CMLCurrent-Mode LogicTier Bvendor application notes (no single standard)
Hamming / SECDEDHamming code and single-error-correct double-error-detect ECCTier Btextbook technique
LVCMOSLow-Voltage CMOS signalling levelsTier BJEDEC JESD8-C, JESD8-5, JESD8-7
Manchester codeManchester (biphase-level) line codeTier BIEEE 802.3 clause 7 (10BASE); textbook
NRZNon-Return-to-Zero line codeTier Btextbook technique (no single spec)
NRZINon-Return-to-Zero Inverted line codeTier Btextbook technique; USB 2.0 Specification ch. 7
OSI modelOpen Systems Interconnection reference modelTier BISO/IEC 7498-1 = ITU-T X.200
PAM44-level Pulse Amplitude ModulationTier BIEEE 802.3bs; PCIe 6.0; JESD239 GDDR7 (PAM3) (verify)
Protocol BuffersProtocol Buffers (Protobuf)Tier BGoogle Protocol Buffers language and encoding guide
Reed–SolomonReed–Solomon codeTier Btextbook; IEEE 802.3 clause 91 (RS-FEC)
SSTL / PODStub-Series Terminated Logic / Pseudo Open DrainTier BJEDEC JESD8-15 (SSTL_18), JESD79-3 (SSTL_15), JESD8-24 (POD12) (verify)
TLVType-Length-Value encodingTier Bgeneric technique (no single spec)
TTL levelsTransistor-Transistor Logic signalling levelsTier BJEDEC JESD8-C (LVTTL); vendor logic-family datasheets

Ready for this book? Ten quick questions

This is the first book of the series. You need school mathematics, a little binary arithmetic and basic digital logic (AND, OR, XOR, a flip-flop). The ten questions below check that. If you miss more than two, read the Start Here guide first; every other idea is taught from zero in this book.

  1. 01Write the decimal number 200 in binary and in hexadecimal.answer

    1100 1000, 0xC8.

  2. 02What is 1011 XOR 0110?answer

    1101.

  3. 03A signal repeats every 2 µs. What is its frequency?answer

    500 kHz.

  4. 04A 3.3 V supply drives 10 mA through a resistor. What is the resistance?answer

    330 Ω.

  5. 05How many different values can 10 bits hold?answer

    1024.

  6. 06What does a D flip-flop do on a rising clock edge?answer

    It copies D to Q.

  7. 07What is 2 to the power 16?answer

    65 536.

  8. 08A file of 1 MB is sent at 8 Mbit/s with no overhead. Roughly how long does it take?answer

    About 1 s (8 Mbit ÷ 8 Mbit/s).

  9. 09In 0x3A, which is the most significant hex digit?answer

    3.

  10. 10What is the name of the sum of all bits modulo 2?answer

    Parity (even/odd).

Book 1 is on 8 career paths

More on this shelf