Unit 7 / 12

Communication Protocols and Network Stack

Gains:

  • Ability to analyze the frame/packet structure of protocols such as I2C/SPI/UART and TCP/IP, MQTT with AI support
  • Ability to narrow down protocol errors (timing, addressing, checksum) as hypotheses with AI
  • Ability to verify AI's protocol interpretation with standard document, analyzer (logic/packet) measurement

A protocol is a set of rules that two devices agree on to understand each other: at what speed, in what order, in what format they will talk. Whether a temperature sensor talks to a microcontroller via I2C or a device talks to a cloud server via TCP/IP and MQTT is based on a protocol. In this unit, you will see how to use AI to analyze protocol frames/packets, narrow down protocol errors, and understand the communications stack (layers on top of each other, from the physical layer to the application). AI is powerful at explaining protocols and generating hypotheses; but what a line actually does is known only by its analyzer measurement (logical analyzer, protocol/packet analyzer) and standard document.

Embedded serial protocols: I2C, SPI, UART

Chips on a board generally talk to three serial protocols:

  • UART: Two lines (TX/RX), no clock line; Both sides must be set to the same speed (baud rate). Simple but synchronization depends on speed.
  • SPI: Clock (SCLK), data input/output (MOSI/MISO) and select (CS) lines; Fast, full duplex, but requires more pins. Clock polarity/phase (CPOL/CPHA) must match on both sides.
  • I2C: Two lines (SDA/SCL), address based, multiple devices on the same line; pull-up resistors and common ground condition. Slow but economical.

AI explains very well how these protocols work, their framework structure, and typical failure causes. Systematically lists possible causes (incorrect address, missing pull-up, speed mismatch, absence of common ground, line contention, cable length/capacitance) when an I2C device becomes unresponsive. But which of these is real can be understood by measuring the line with a logic analyzer and looking at the SDA/SCL waves; AI gives the hypothesis, measurement decides.

Tip: In a serial protocol failure, ask the AI ​​"rank the possible causes from most likely to least likely, and whatever I see on the analyzer for each is confirmed." This way you make the measurement targeted; Instead of trying each reason one by one, the analyzer view takes you to the right branch.

Network protocols: TCP/IP, UDP, MQTT, CoAP

Layered protocols come into play as devices connect to the network and cloud. The TCP/IP stack is essentially layered: physical/data link (Ethernet, Wi-Fi), network (IP: addressing and routing), transport (TCP: reliable, sequential, flow-controlled / UDP: fast, trustless), and application (HTTP, MQTT, CoAP). Key concepts:

  • TCP vs UDP: TCP compensates for loss and guarantees order but introduces latency and overhead; UDP is fast but has no delivery guarantee (real-time audio/video preferred for telemetry).
  • MQTT: Lightweight IoT messaging protocol that works with the publish-subscribe model; messaging via topics via a broker. QoS levels set delivery assurance.
  • CoAP: HTTP-like, UDP-based lightweight protocol for restricted devices.

AI analyzes the frame/packet structure of these protocols, helps you interpret a Wireshark (packet analyzer) capture, and reviews an MQTT topic design. But what the real traffic is is verified by packet capture, and the server behavior is verified by real testing.

Checksum, CRC and framing

Most protocols use a checksum or CRC (Cyclic Redundancy Check) to check that data is not corrupted: the sender calculates a verification value from the data, the receiver does the same calculation and compares. AI describes and writes code for CRC/checksum calculation, but details such as polynomial selection, endianness, initial value etc. are specific to the standard; The CRC code generated by the AI ​​must be compared verbatim to the official definition of the protocol and verified against a known test vector.

three mini cases

Case 1 — Incomplete pull-up. A team cannot run an I2C sensor on a breadboard; does not acknowledge the device address (no ACK). AI lists missing pull-up resistor and common ground as the most likely cause. When looking at the SDA line with a logical analyzer, it is seen that the signal cannot fully reach the high level; Communication starts when pull-up resistors are added. Lesson: AI highlighted the most likely cause, the analyzer confirmed it.

Case 2 — Wrong SPI mode. An engineer reads gibberish data from an SPI device. AI suggests clock polarity/phase (CPOL/CPHA) mismatch as the possible cause. In the analyzer, the clock appears to sample differently than the edge the device expects; When the mode is corrected, the data becomes meaningful. Lesson: The "data but nonsense" symptom in SPI is most often mode mismatch; measurement makes this clear.

Case 3 — MQTT QoS misunderstanding. An intern sends telemetry via MQTT but sees some messages are lost and asks the AI. AI states that QoS 0 is “at most once, delivery is not guaranteed”; Explains that QoS 1/2 is required to guarantee delivery, but this introduces overhead and delay. The intern switches to QoS 1 based on telemetry criticality and verifies the broker behavior with real testing. Lesson: Explain the AI ​​protocol option; The correct choice is made according to the application and verified by testing.

Copiable prompt templates

PROTOCOL FAILURE NAVIGATION TEMPLATE"[I2C/SPI/UART/TCP/MQTT] communication has the following symptom: [symptom]. Rank the possible causes from MOST LIKELY to Least likely. For each cause: (1) why does it give this symptom, (2) whatever I see on the analyzer/measurement is CONFIRMED, (3) whatever I see is ELIMINATED. DO NOT MAKE a definitive diagnosis; I narrow down by measurement. decision tree emerges."

FRAMEWORK/PACKET ANALYSIS TEMPLATE "Break the following [I2C/SPI/UART byte array / packet capture] content into fields and describe each field (address, command, data, checksum/CRC, flag). State clearly your assumption about endianness and bit order. Note that I need to verify your comment with the official description of the protocol and a test vector. Data: [paste]."

CRC/CHECKSUM VERIFICATION TEMPLATE"Describe CRC/checksum calculation for [protocol]: polynomial, initial value, bit order, final

PROTOCOL SELECTION TEMPLATE"Conduct transport/application protocol comparison for the following application: [requirement: delivery guarantee, latency, power, bandwidth, device constraint]. Compare TCP/UDP and MQTT/CoAP/HTTP options with these criteria. DO NOT IMPOSE a clear choice; balance each option and state that the choice should be verified by actual testing."

Weak prompt / Strong prompt

WEAK PROMPT: "I2C is not working, why?"

STRONG PROMPT: "My I2C sensor does not ACK (address not acknowledged). List the possible causes starting from the most likely: pull-up, common ground, wrong address, speed, cable capacitance, contention. For each cause, write whatever I see on the SDA/SCL on the logic analyzer is confirmed, whatever I see is eliminated. Don't make a diagnosis; I want a list that I can narrow down by measurement."

The weak prompt produces a single guess; The powerful prompt provides a diagnostic map that can be narrowed down to measurement, ordered and verifiable.

Protocol comparison chart

protocol

Type

strong point

verification tool

UART

Series, without clock

Simple, two lines

Logical analyzer

SPI

Serial, clocked

Fast, full duplex

Logical analyzer (CPOL/CPHA)

I2C

Serial, addressable

Many devices, few pins

Analyzer (ACK, pull-up)

TCP

network, transport

Reliable, in order

Packet analyzer (Wireshark)

UDP

network, transport

Fast, low latency

packet analyzer

MQTT

Application

Lightweight, pub/sub, QoS

Broker log + packet capture

Caution: Having the AI interpret a protocol capture is fast, but the AI may incorrectly assume the bit order or field boundary. Verify each analysis against the official description of the protocol and a known test vector.

Common mistakes

  • Changing it based on AI prediction without measuring the fault cause. The analyzer view leads you to the right cause.
  • Ignoring CPOL/CPHA compliance in SPI. "There is data but it's nonsense" is often a mode incompatibility.
  • Forgetting pull-up and common ground on I2C. It is the most common cause of "not working at all".
  • Assuming CRC parameters. Polynomial, start, bit order are specific to the standard; It is verified with the test vector.
  • Confusing MQTT QoS with delivery guarantee. QoS 0 does not guarantee; The selection is made and tested according to the application.

In summary

In this unit you have used AI as a powerful aid in explaining protocols such as I2C/SPI/UART and TCP/IP, MQTT, frame/packet analysis and systematically narrowing down fault causes. But protocols are precise and standard-bound: what a line actually does is determined by a logic/packet analyzer, the accuracy of an analysis is determined by the formal definition and test vector, the cause of a fault is determined by measurement. Direct the AI ​​to give “the most likely cause and the measurement to confirm it”; Let the analyzer and the standard decide.

Application task

Select a serial protocol failure scenario (e.g. no I2C ACK). Request a sequential and measurement-verifiable diagnostic map from AI with the “protocol fault narrowing” template. Then take a sample byte array (e.g. a sensor reading frame) and space it with the "Frame/packet parsing" pattern and note the endianness assumption. Finally, verify a CRC code against a known test vector with the "CRC/checksum verification" template.

checklist

  • [ ] I confirmed the cause of the failure by analyzer measurement, not by AI prediction.
  • [ ] I listed CPOL/CPHA on SPI, address/pull-up/common ground control on I2C.
  • [ ] I compared the frame/packet parsing with the official protocol definition.
  • [ ] I verified the CRC/checksum parameters with the test vector.
  • [ ] I made the transport/application protocol selection according to the requirement and tested it with real testing.
  • [ ] I have correctly interpreted the delivery guarantee meaning of MQTT QoS.