Independent learning for embedded-systems engineersHardware · Firmware · Software
TEA-104CORE EMBEDDED SYSTEMS TOPICFOUNDATION

Communications interfaces and protocols

Turn electrical connections into dependable contracts: select the right interface, define meaning and timing, and design explicitly for corrupted, delayed, duplicated and missing data.

After this module, you should be able to:

  • Separate physical, data-link and application concerns
  • Select an interface from system constraints
  • Specify a testable protocol contract
  • Design and verify failure behaviour

Study guide · Updated · About 9 minutes reading + 20–30 minutes practice

Before you start: Read TEA-101 and TEA-102. Recognise the distinction between a physical link and message semantics.

01 / SYSTEM VIEW

An interface is a boundary; a protocol is an agreement.

A connector and peripheral do not define communication. Dependable exchange needs compatible electrical behaviour, framing, message meaning, timing, ownership and failure responses at both ends.

Layering helps engineers reason about faults. A valid electrical waveform may contain an invalid frame; a valid frame may contain a command that is stale, unsafe in the current state or incompatible with the receiver’s version.

PHYSICALCan bits cross the boundary?Levels, topology, termination, isolation, shielding and connectors
TRANSFERCan frames be exchanged?Arbitration, addressing, framing, integrity, acknowledgement and flow control
APPLICATIONDo both ends agree?Commands, units, states, timing, validity, permissions and versions
Transport reliability is not system safety.A checksum can show that received bits match transmitted bits. It cannot show that the value is fresh, plausible, authorised or appropriate for the current system state.
02 / SELECTION

Select from constraints, not familiarity.

InterfaceUseful characteristicsQuestions and limitations
UART / serialSimple point-to-point link; easy to observe and bring up.Define framing, level translation, flow control and recovery from lost byte alignment.
I²CLow pin count and addressed peripherals on one board.Consider pull-ups, capacitance, clock stretching, stuck-bus recovery and address conflicts.
SPIHigh throughput, low protocol overhead and deterministic local transfer.Chip-select scaling, no standard message semantics and device-specific timing.
CANRobust shared bus, arbitration and strong frame-level error handling.Bus loading, message priorities, physical topology and the selected higher-layer protocol.
USBStandard host/device ecosystem, power options and defined device classes.Host dependency, enumeration, cable removal, class behaviour and update compatibility.
Ethernet / IPScalable networking and access to mature transport protocols.Variable latency, configuration, congestion, security and loss of network services.
WirelessNo cable and support for mobile or distributed products.Interference, coexistence, range, pairing, credentials, power and regulatory constraints.

Selection criteria should include distance, data rate, maximum latency, topology, environment, EMC, isolation, power, update needs, security, component availability, diagnostics and the consequences of communication loss.

03 / CONTRACT

Specify what each endpoint can depend upon.

  1. Define ownership. State who initiates, who may command, who publishes state and who decides that a link has failed.
  2. Define messages. Give every field a type, byte order, scale, unit, valid range and reserved-value rule.
  3. Define framing and integrity. Specify boundaries, length, sequence information, error detection and acknowledgement.
  4. Define timing. Include rates, deadlines, timeouts, retry limits, freshness and behaviour during overload.
  5. Define states. Cover start-up, discovery, synchronisation, normal exchange, degraded operation, reconnection and shutdown.
  6. Define compatibility. State how versions are identified, negotiated, rejected and updated.
  7. Define trust. Address authentication, authorisation, confidentiality and replay resistance where the threat model requires them.

Worked example: host computer to motor controller

A host sends cycle commands to an MCU over USB virtual serial. A safer contract separates command acceptance from command completion.

Framed command + sequenceSyntax and state checkAccepted / rejectedControlled executionCompletion + resultHeartbeat monitored

The controller rejects duplicates and commands that are invalid in its current state. If the heartbeat expires, it completes only the current bounded safe action, removes drive energy and reports the interruption after reconnection. Retries are bounded so a communications fault cannot create an endless command loop.

04 / EVIDENCE

Verify both conformance and resilience.

Interface specification

Physical details, message definitions, timing, states, error handling, versions and security properties.

Budget analysis

Bandwidth, bus loading, latency, buffers, retry traffic and worst-case utilisation.

Compatibility record

Supported endpoint combinations, negotiation rules and regression results.

Fault-injection results

Corruption, truncation, delay, duplication, reordering, disconnection and reconnection.

Protocol traces

Time-correlated captures that show actual messages, states and response times.

Security verification

Unauthorised commands, malformed input, replay, downgrade and resource-exhaustion tests.

Common failure patterns

Happy-path protocol

The message list is defined, but partial frames, restarts and missing responses are not.

Unbounded retry

Recovery traffic increases congestion or repeats an unsafe physical action.

Hidden units and scaling

Endpoints interpret the same integer differently, often without an obvious communication error.

Version by assumption

Independently updated endpoints connect without an explicit compatibility decision.

05 / DEEPER LEARNING

Separate electrical transport from application meaning

UART, I²C, SPI and CAN describe different interface arrangements and capabilities. Their successful operation does not define the meaning of a product command. Specify voltage levels, grounding, topology, termination where relevant, addressing and timing alongside the application message contract.

For a serial message, define framing, byte order, length limits, units, legal values, version and error detection. Separate the parser from the function that changes product state. Validate a whole request before acting so a later invalid field cannot leave a half-applied command.

Set bounds for incomplete frames and noisy inputs. A parser that waits indefinitely for a missing terminator can block valid traffic. A parser that allocates memory from an untrusted length can exhaust the device. Check maximum-size messages, malformed lengths and resynchronisation after an error.

06 / DEEPER LEARNING

Distinguish acceptance, completion and retry

An acknowledgement can mean bytes arrived, a request passed validation, work was queued or a physical action completed. Name the meaning explicitly. For asynchronous actions, report acceptance separately from completion and carry an operation identifier through both responses.

If the sender loses a completion response, retrying a command may repeat an irreversible action. Define idempotency: repeating the same request either has the same effect or is recognised as a duplicate. State how identifiers behave across reset and how long duplicate records remain valid. No transport acknowledgement by itself guarantees exactly-once physical execution.

Choose timeouts from response budgets and product behaviour. Reconnection does not establish that the endpoints agree on state. Exchange session identity, versions and the outstanding operation state before enabling new work.

EventContract decision
Duplicate requestReturn the recorded outcome or reject according to the operation identity.
Unsupported versionNegotiate an approved version or remain unavailable with a clear reason.
Checksum failureDiscard the frame and preserve synchronisation without partial action.
Link loss during motionApply the local, hazard-derived response and report it after reconnection.
07 / DEEPER LEARNING

Verify the interface under competing traffic

Test communication while acquisition, logging, update and fault processing are active. Electrical robustness and software load interact: a burst of receive interrupts can delay control even when every byte is valid. Bound the amount of work performed per interrupt or scheduling cycle.

Use independent observations at both endpoints. Record message time, operation identity and physical outcome. Include delayed, repeated, reordered and truncated messages where the transport permits them, plus disconnects at state boundaries. A checksum detects certain accidental corruption patterns; it does not authenticate a sender or prevent an attacker from generating a new valid checksum.

08 / APPLY THE LEARNING

Practical exercise

An illustrative engineering exercise; values are assumptions for this lesson.

Prevent a repeated dispense after a lost reply

A controller accepts Dispense(request ID, volume), performs the action and sends Complete. The Complete reply is lost, so the host resends the same request.

  1. Define acceptance, completion and duplicate handling.
  2. Specify what happens if the controller resets after dispensing but before retaining the outcome.
  3. Propose three interface tests that inspect physical delivery.
Show the worked answer

The controller should own operation execution and recognise a repeated identifier within an agreed session and retention model. It can return the known status without dispensing again. Acceptance confirms responsibility for the request; completion reports the verified outcome and any uncertainty.

A reset can create an uncertain interval between physical action and durable recording. Do not promise exactly-once behaviour unless the full mechanism supports it. A defensible policy may inhibit automatic retry, preserve an incomplete-operation record and require reconciliation using available physical evidence or an authorised user. Test a lost acceptance, a lost completion and power interruption at the physical-action boundary. Measure delivered volume as well as protocol responses.

Review criteria

  • Replies distinguish acceptance from physical completion.
  • Restart uncertainty is explicit.
  • Duplicate tests observe the physical effect, not only packet counts.
09 / SELF-REVIEW

Check your understanding

Does a CRC make a service command trustworthy?

No. It addresses accidental corruption, not authority. Authentication, authorisation and semantic validation need separate controls.

What must reconnection establish?

Compatible versions, a new or continuing session, valid state and the disposition of outstanding work before operation resumes.

11 / REFERENCES

Further learning

KEY TAKEAWAY

Specify the failure semantics, not only the message format.

A dependable interface states what is exchanged, when it is valid, who owns each decision and what both endpoints do when communication fails.