Metatransformer report
Communication protocols as contracts
Practice · 70 minutes · Frame and validate messages while separating electrical signaling, byte transport, and application meaning for easier fault isolation.
Text report: images and diagrams are omitted, and links to project files are inactive. Keep the exported project alongside this PDF for wiring diagrams, models, and linked files.
Learning outcomes
- Design and trace a bounded message frame with addressing, length, error detection, timeout, and a documented retry policy.
Prerequisites
- mcu-gpio
- digital-interfaces
Concepts
Devices communicate only when several agreements line up. The wire-level layer defines voltage, timing, and who may drive. A transport convention groups bits into bytes. An application protocol says that a particular byte means temperature, motor command, or error. Separating these layers helps diagnosis: clean electrical edges do not prove that two devices agree about byte order or units.
UART sends framed bytes asynchronously using an agreed baud rate. I²C shares clock and data among addressed devices and uses open-drain lines with pull-ups. SPI commonly uses a clock, two data directions, and a chip-select per target. Names alone do not guarantee voltage compatibility, pin assignment, mode, speed, or connector orientation. For an I²C sensor cable, choosing pull-up resistance involves bus capacitance and device sink current; blindly adding multiple breakout-board pull-ups can make the combined resistance too low.
At the message layer, a bounded frame might contain sync, version, type, length, payload, and checksum. If payload length is L, the receiver must reject L above its allocated capacity before copying. A simple sum checksum detects some corruption but not all; stronger CRCs provide specified detection properties. Timeout and retry rules must consider whether repeating a command is safe. “Set speed to 40%” is idempotent; “advance 10 mm” may execute twice unless it carries a sequence number and duplicate handling.
A common misconception is that a checksum provides security or proves semantic correctness. It only detects a class of accidental changes; a perfectly checksummed command can still use the wrong units. Another failure is endlessly waiting for a missing byte, freezing the robot. The build decision is to cap frame length, set a timeout based on baud and maximum frame size, and expose distinct errors—timeout, invalid length, checksum, unsupported version—so fault isolation is possible.
Worked example
Problem
A UART link runs at 115,200 bit/s using 8 data bits, one start bit, and one stop bit. Estimate transmission time for a 32-byte frame and choose a timeout with 3× margin.
Steps
- Each byte occupies 10 transmitted bits, so the frame uses 32 × 10 = 320 bits.
- Ideal wire time = 320 / 115,200 s = 0.00278 s = 2.78 ms.
- A 3× wire-time margin gives 8.33 ms; choose a practical 9 ms or larger value after accounting for sender scheduling.
Result
The ideal wire time is about 2.78 ms; a starting receive timeout of 9 ms supplies slightly more than 3× margin, subject to system scheduling tests.
Sanity check
At roughly 11,520 bytes/s, 32 bytes should take about 32/11,520 s, which is the same 2.78 ms.
Check your understanding
A receiver gets a valid-checksum command ADVANCE 10 mm, sends no acknowledgement because the reply is lost, and the sender retries. What protocol feature prevents an unintended 20 mm move?
A. A brighter status LED B. A unique sequence number with receiver-side duplicate detection and cached acknowledgement C. A longer payload without any identifier D. Removing the timeout so the sender waits forever
Your answer: ______________________________
Reasoning:
Answer key
ANSWER KEY — check only after attempting the question.
B. A unique sequence number with receiver-side duplicate detection and cached acknowledgement
A sequence number lets the receiver recognize the retry as the same operation and return the prior result without executing again. Checksums only test frame corruption. Extra anonymous bytes add no identity, while waiting forever converts packet loss into a permanent system hang.
Hands-on lab
Goal
Implement a small serial frame parser and diagnose truncation, corruption, and duplicate commands from captured bytes.
Equipment
- Microcontroller and USB serial link or two logic-level boards
- serial terminal
- jumper wires if using two boards
- logic analyzer optional
Procedure
- Define a frame with version, sequence, type, length up to 16, payload, and an explicitly named checksum algorithm.
- Write the receiver as a state machine with a bounded buffer and timeout; log accepted sequence numbers and error categories.
- Send one valid idempotent LED-duty command and confirm its acknowledgement.
- Introduce deliberate faults one at a time: wrong checksum, declared length 17, and a truncated frame; verify distinct rejection paths.
- Repeat the valid frame with the same sequence number and verify it is acknowledged but not applied twice.
What to observe
- Expected: valid frames change the test output once; corrupt, oversized, or incomplete frames do not change it.
- Record actual transmitted hex bytes, receiver log, and elapsed timeout; expected acceptance is not evidence of receipt.
- Expected fault signatures are checksum error, length error, and timeout respectively, rather than one generic failure.
Transfer challenge
Write the layer-by-layer checks for a screen module that powers up but shows no sensor values: voltage/ground, bus pins and pull-ups, address, frame fields, then units.
Cautions
- Confirm both boards use compatible logic voltage and a common ground before wiring; never connect RS-232, automotive, or appliance-level signals directly.
Evidence record
Learner: ____________________ Date: ____________________
Evidence artifact or file: ____________________________________________
| Item | Record |
|---|---|
| Prediction or expected result | |
| Actual observation or measurement | |
| Conditions and tools used | |
| Difference from expectation | |
| Next decision or follow-up |
Notes: