63. Integration, Buffering and Reliability

Question.2

A protocol engine is transmitting an active word when the system writes the next word.

Which architecture protects the active transfer while allowing the new word to be prepared?

Need Help? Refer to the Quick Guide below

Serial-interface hardware converts protocol rules into digital circuits.

Serial Communication Interfaces Architecture Block Diagram

1. Serial Communication Hardware Design Fundamentals

Timing Source for Each Interface

InterfaceTiming SourceHardware Action
UARTLocal clockRebuild the receive sample timing.
SPIHost-generated SCKGenerate sample and change events.
I²CShared SCLRelease SCL, then observe SCL_Bus.
CANLocal bit timerSynchronize to shared-bus edges.

Timing Measurement Terms

InterfacePreferred TermMeaning
UARTBaud rateSymbols per second
UARTBit rateBits per second
SPISCK frequencyClock cycles per second
I²CSCL frequencyClock cycles per second
CANBit rate or bit timeBits per second or time per bit

In binary UART, one symbol normally carries one bit.

Therefore, its baud rate and bit rate have the same numerical value.

Serial Bit Order

InterfaceBit Order
UARTD0 first, D7 last
SPI8-bit word, MSB first in this architecture
I²CMSB first
CANDefined by the frame fields

Important: The TX and RX datapaths must use the same bit order.

Common Serial Controller Hardware

Common Serial Controller Hardware
Protocol NeedDigital Hardware
Bit timingCounter and tick generator
Frame positionBit counter and state register
TX bit selectionMUX or shift register
RX bit captureSample enable and receive register
Bus ownershipOutput-enable or release control
Error detectionComparator and status register

Circuit scope: Each figure shows one learning-focused circuit block rather than a complete UART, SPI, I²C, or CAN peripheral.

2. UART Hardware Design

UART Frame Format

NameIdleStart BitData BitsParity BitStop Bit
Labels / ValuesIdle = 10D0 to D7, LSB firstP = Even/Odd, or omitted1

UART Transmitter Hardware

A TX request is accepted only while the transmitter is idle.

TX_Accept = TX_Start · Busy'

At TX_Accept:

  • Capture TX_Data.
  • Capture the parity setting.
  • Clear the frame counter.
  • Set Busy = 1.

Later input changes do not affect the active frame.

A new request during Busy = 1 is ignored unless a buffer is provided.

BlockFunction
TX data registerHolds the accepted byte
Parity logicGenerates P
Frame counterSelects the active frame field
Frame MUXSelects 0, D0...D7, P, or 1
Baud-tick inputExternal Baud_Tick advances the active frame
TX registerHolds one serial bit
Control logicGenerates Busy and Done
Even_Parity = D0 ⊕ D1 ⊕ D2 ⊕ D3 ⊕ D4 ⊕ D5 ⊕ D6 ⊕ D7
Odd_Parity  = Even_Parity'

If parity is disabled, the frame MUX skips P.

UART Transmitter
Learning-oriented UART transmitter with a captured data register, compact parity logic, external Baud_Tick input, frame counter, frame MUX, TX register, Busy, and Done

Direct-I/O simplification: TX_Start, TX_Data, parity settings, and Baud_Tick are shown as direct inputs. In a complete system, control/configuration registers and the baud generator normally provide them.

UART Baud-Tick Generation

For an integer divider:

Baud_Divider = f_CLK_SYS / f_BAUD

The implemented learning circuit uses a 4-bit programmable Baud_Divider. It first generates the terminal limit:

Baud_Limit = Baud_Divider - 1

Implementation note: 1111, the 4-bit two's-complement value of -1, is wired directly to the adder's B input while Baud_Divider drives A. The normal adder therefore computes Baud_Divider - 1; no controlled SUB configuration is used.

The value of Baud_Divider must not be 0000

The four counter D flip-flops expose Baud_Count[3:0]. A second 4-bit full adder forms:

Count_Sum = Baud_Count + Enable

Thus Enable = 0 holds the count, while Enable = 1 increments it. A 4-bit magnitude comparator produces:

Terminal_Count = (Baud_Count = Baud_Limit)
Baud_Tick      = Enable · Terminal_Count

Each counter-register input masks its corresponding Count_Sum bit with Baud_Tick':

Baud_Count_Next[i] = Count_Sum[i] · Baud_Tick'

Consequently, the counter increments while enabled and below Baud_Limit, generates a one-CLK_SYS-cycle Baud_Tick at the terminal count, and synchronously returns to 0000.

Active-LOW nRESET also clears the four counter flip-flops. The separate UART transmitter circuit receives Baud_Tick as an input, keeping frame sequencing independent of the selected system-clock and baud-rate values.

Four-bit UART baud-tick generator with Baud_Divider entering a full adder whose B input is the fixed two's-complement value 1111 to form Baud_Limit, a four-DFF enabled counter and incrementer, a magnitude comparator for Terminal_Count, and Enable-gated one-cycle Baud_Tick reset logic.

Direct-I/O simplification: Baud_Divider and Enable are direct inputs in this circuit. A complete UART normally receives them from configuration and control logic.

UART Receiver Sampling

The learning circuit is a fixed 8-N-1 receiver. It uses a synchronized RX input and an external 16× Oversample_Tick.

It generates one Sample_Enable near the center of each bit.

Why wait half a bit? The detected falling edge marks the approximate start-bit boundary and may also be caused by a short disturbance. Waiting eight oversample ticks moves the check to the center of the start bit, away from either edge. If RX_SYNC is still LOW there, the start bit is accepted; otherwise it is rejected as a false start.

RX Receiver Sampling
BlockFunction
RX synchronizerProduces stable local RX
Start detectorFinds a possible start edge
4-bit sample counterLocates the bit center and full-bit boundaries
Sample decoderPulses Sample_Enable
3-bit bit counterSelects data bits D0 through D7
RX registerCaptures data bits
Four-state one-hot controllerSequences IDLE, START, DATA, and STOP
Stop checkProduces RX_VALID or FRAME_ERROR

1. Synchronize and detect the start edge

Two D flip-flops synchronize RX; a previous-value register then detects the HIGH-to-LOW transition:

Start_Detect = RX_PREV · RX_SYNC'

2. Enable receiver timing

The sample counter runs only while the receiver is validating or receiving a frame:

Timing_Enable = S_START + S_DATA + S_STOP
Count_Enable  = Oversample_Tick · Timing_Enable

3. Validate the start-bit center

Count 8 represents half of a 16× bit interval:

Count_8  = C3 · C2' · C1' · C0'
Half_Bit = S_START · Oversample_Tick · Count_8

At Half_Bit, LOW accepts the start bit and HIGH returns the controller to idle as a false start.

4. Sample the eight data bits

After start validation, count 15 produces one full-bit sampling interval:

Count_15      = C3 · C2 · C1 · C0
Bit_Time      = Oversample_Tick · Count_15
Sample_Enable = S_DATA · Bit_Time

Bit_Count[2:0] selects D0 through D7. The RX register loads only the selected bit when Sample_Enable = 1.

5. Finish the frame and check the stop bit

Last_Data_Sample = Sample_Enable · B2 · B1 · B0
Stop_Sample      = S_STOP · Bit_Time
RX_VALID         = Stop_Sample · RX_SYNC
FRAME_ERROR      = Stop_Sample · RX_SYNC'

Sample_Count[3:0] and Bit_Count[2:0] are exposed as learning/debug outputs.

Important: The RX register captures only when Sample_Enable = 1.

Learning-oriented 8-N-1 UART receiver with a two-DFF RX synchronizer, previous-RX start detector, four-state one-hot controller, 4-bit sample counter, 3-bit data-bit counter, RX register, RX_VALID, and FRAME_ERROR, driven by external Oversample_Tick.

Direct-I/O simplification: Oversample_Tick is supplied directly. A complete UART normally derives this 16× timing pulse from its programmable baud-rate generator.

UART Receive Status

SignalSet WhenIncluded in the learning circuit?
FRAME_ERRORSampled stop bit is 0Yes
RX_VALIDSampled stop bit is 1 and reception completesYes
PARITY_ERRORReceived parity does not matchNo; the circuit is 8-N-1
OVERRUNNew data arrives before old data is readNo; buffering is omitted

False starts do not assert RX_VALID.

Scope note: A production receiver must protect unread data and report overrun. The pictured learning circuit intentionally omits that buffer/handshake layer.

UART Implementation Steps

  1. Build the standalone baud-tick divider shown above.
  2. For TX, capture the active byte and parity configuration only on TX_Accept.
  3. Advance the TX frame counter with external Baud_Tick and select start, data, optional parity, and stop fields.
  4. For RX, synchronize RX and detect its falling start edge.
  5. Use external Oversample_Tick, the 4-bit sample counter, and the four-state controller to validate the start bit and generate Sample_Enable.
  6. Count and store D0 through D7, then sample the stop bit.
  7. Generate TX Busy/Done and RX RX_VALID/FRAME_ERROR.
  8. Verify reset, idle, complete stop-bit timing, and false-start behavior.

3. SPI Hardware Design

SPI Transfer Format

PropertyValue
Word size8 bits
Bit orderMSB first
Data flowFull duplex
Clock sourceHost-generated SCK
Target selectActive-low CS_n

SPI can also use another bit order when required by the connected device.

Clock Idle and Active Edges

CPOL selects the idle level of SCK.

CPOLSCK IdleIdle → ActiveActive → Idle
0LOWRising edgeFalling edge
1HIGHFalling edgeRising edge

CPHA selects the action performed on each edge.

CPHAIdle → ActiveActive → IdleFirst TX Bit
0SampleChangePreload before the first edge
1ChangeSampleLaunch on the first edge
  • Sample: Capture the input bit into the RX register.
  • Change: Update the output bit from the TX register.

SPI Mode Mapping

ModeCPOLCPHASCK IdleIdle → ActiveActive → Idle
000LOWRising: SampleFalling: Change
101LOWRising: ChangeFalling: Sample
210HIGHFalling: SampleRising: Change
311HIGHFalling: ChangeRising: Sample

Configurable SPI Edge Generator

SignalMeaning
ClockSystem clock for the phase flip-flop
nRESETActive-LOW reset that returns Phase to 0
EnableAllows SPI phase changes while a transfer is active
Half_TickOne-cycle event marking one half of an SCK period
CPOLSelects the idle level of SCK
CPHASelects which phase transition samples data and which changes data
PhaseStored half-cycle state; 0 is idle phase and 1 is active phase
SCKGenerated SPI serial clock, CPOL ⊕ Phase
Idle_to_ActivePulse for the first transition away from the idle clock level
Active_to_IdlePulse for the return transition to the idle clock level
Sample_EdgeEvent used to capture the received data bit
Change_EdgeEvent used to update the transmitted data bit

The learning circuit treats Half_Tick as an external half-period timing pulse. A complete SPI host may generate it with a separate divider, but that divider is not part of this circuit.

The phase T flip-flop toggles only while the controller is enabled:

T_Phase = Enable · Half_Tick
Phase = 0 means the idle half-cycle.

SCK = CPOL ⊕ Phase

The phase transition creates two internal events:

  • Idle_to_Active
  • Active_to_Idle

CPHA maps these events to the datapath enables.

Idle_to_Active = Enable · Half_Tick · Phase'
Active_to_Idle = Enable · Half_Tick · Phase

Sample_Edge = CPHA'·Idle_to_Active + CPHA·Active_to_Idle
Change_Edge = CPHA·Idle_to_Active + CPHA'·Active_to_Idle
EventDatapath Action
Sample_EdgeCapture MISO
Change_EdgeUpdate MOSI


 

Learning-oriented SPI edge controller with external Enable and Half_Tick inputs, one phase T flip-flop, CPOL XOR clock generation, phase-transition decoders, and CPHA-selected Sample_Edge and Change_Edge outputs.

Direct-I/O simplification: Enable, Half_Tick, CPOL, and CPHA are direct inputs, while Sample_Edge and Change_Edge are exposed outputs. In a complete SPI host, the transfer controller, timing divider, configuration registers, and datapath connect these signals internally.

SPI Transfer Sequence

SPI Transfer Sequence

SPI TX and RX Datapaths

PathSourceEnableAction
TXTX register MSBChange_EdgeAdvance MOSI
RXMISOSample_EdgeCapture into RX register

For CPHA = 0, preload the first MOSI bit before the first sample.

For CPHA = 1, the first Change_Edge launches the first bit.

Target Selection and Completion

StageController Action
StartLatch the target and assert one CS_n
TransferHold the selected target constant
Final sampleFinish the required clock phase
CompleteSet SCK = CPOL, release CS_n, pulse Done

Caution: Do not release CS_n before the last clock phase is complete.

Mode-0 Target Behavior

ConditionTarget Action
CS_n = 1Ignore SCK
Target selectedPreload first MISO bit
Rising SCK edgeSample MOSI
Falling SCK edgeUpdate MISO

SPI Implementation Steps

  1. Supply Enable and the external half-period pulse Half_Tick.
  2. Toggle the phase flip-flop with T_Phase = Enable · Half_Tick.
  3. Generate SCK = CPOL ⊕ Phase so disabled/reset phase returns the clock to its configured idle level.
  4. Decode Idle_to_Active and Active_to_Idle from the current phase.
  5. Map the two transition events to Sample_Edge and Change_Edge with CPHA.
  6. In a larger SPI design, use those outputs as RX-capture and TX-update enables.

4. I²C Hardware Design

Open-Drain Bus Operation

Control ValueParticipant Action
0Pull the line LOW
1Release the line

The participant does not actively drive HIGH.

Participant OutputsResolved Bus
Every participant releasesHIGH
Any participant pulls LOWLOW

Resolved SDA and SCL Hardware

For release-valued controls:

SDA_Bus = Controller_SDA_Release
          · Target0_SDA_Release
          · Target1_SDA_Release

SCL_Bus = Controller_SCL_Release
          · Target0_SCL_Release
          · Target1_SCL_Release

Every device observes SDA_Bus and SCL_Bus.

It does not rely only on its intended output.

The learning circuit implements these equations with two independent native 3-input AND gates: one for SDA and one for SCL. It models one controller and two targets and contains no clock, state machine, or physical pull-up resistor model.

I2C resolver circuit that combines controller and target release controls so any LOW request forces the resolved SDA or SCL bus LOW.

Direct-I/O simplification: The controller and target SDA/SCL release controls are direct inputs here. In a complete I²C design, each participant's protocol controller generates these signals.

Important: Intended output and observed bus value may be different.

I²C Bus Events

EventSDA_Bus ActionSCL_Bus Level
STARTHIGH → LOWHIGH
STOPLOW → HIGHHIGH
DataStableHIGH
Repeated STARTHIGH → LOWHIGH, without STOP

The implemented timing circuit observes the resolved bus with previous-value D flip-flops:

START_Detect = SDA_PREV · SDA_Bus' · SCL_Bus
STOP_Detect  = SDA_PREV' · SDA_Bus · SCL_Bus
SCL_Rise     = SCL_PREV' · SCL_Bus

START_Detect sets an Active transaction register, and STOP_Detect clears it. While active, a 4-bit full-adder-based counter increments on each SCL_Rise:

D_Active    = START_Detect + Active · STOP_Detect'
Count_Enable = Active · SCL_Rise
Count_Clear  = START_Detect + ACK_Sample + STOP_Detect

The counter uses Bit_Count + Count_Enable and a synchronous clear mask; protocol events are not connected to the counter's asynchronous clear pins. After eight data clocks:

Byte_Complete = B3 · B2' · B1' · B0'
ACK_Window    = Active · Byte_Complete
ACK_Sample    = ACK_Window · SCL_Rise

ACK_Detect  = ACK_Sample · SDA_Bus'
NACK_Detect = ACK_Sample · SDA_Bus

The ninth rising SCL edge therefore samples ACK or NACK and synchronously restarts the byte counter. The same START detector also recognizes a repeated START while Active = 1.

Learning-oriented I2C timing detector with previous-SDA and previous-SCL registers, START and STOP detection, Active tracking, a 4-bit SCL-rise counter, eighth-bit ACK window, and ninth-clock ACK and NACK detection.

Direct-I/O simplification: SDA_Bus and SCL_Bus are direct inputs to this timing circuit. In the combined system, they come from the open-drain bus resolver or physical input interface.

Address and ACK Ownership

The controller sends a 7-bit address and R/W.

The address is sent MSB first.

Bus PhaseSDA OwnerSDA Action
Address or data bitsByte transmitterPull LOW for 0; release for 1
ACK bitByte receiverPull LOW for ACK; release for NACK

The ownership circuit is a single 2:1 MUX using release-valued logic:

SDA_Release = ACK_Window' · TX_Bit
            + ACK_Window · ACK_Release

When ACK_Window = 0, TX_Bit controls SDA. When ACK_Window = 1, the byte receiver's ACK_Release value controls SDA. This circuit does not generate the address, data, or ACK decision; it only performs the ownership handoff.

A target ACKs only a matching address and supported direction.

After a mismatch, it releases SDA until STOP or a new START.

Learning-oriented I2C SDA ownership circuit implemented as one 2-to-1 MUX selecting TX_Bit when ACK_Window is low and ACK_Release when ACK_Window is high, producing release-valued SDA_Release

Direct-I/O simplification: TX_Bit, ACK_Release, and ACK_Window are direct inputs. A complete I²C controller normally generates them from its shift register, ACK decision logic, and timing state.

Caution: The byte transmitter must release SDA during the ACK bit.

I²C Controller Sequence

I2C Controller Sequence

A normal transaction starts only when both bus lines are HIGH.

Repeated START is the exception.

Clock-Stretch Detection

When the controller wants SCL HIGH, it sets SCL_Release = 1.

The controller then checks the resolved bus.

Advance_High_Phase = SCL_Release · SCL_Bus
SCL_ReleaseSCL_BusAction
10Wait
11Advance or sample

Arbitration-Loss Detection

Check arbitration during controller-owned address and data bits.

Arbitration_Lost_Detect =
Arbitration_Enable · SDA_Intent · SDA_Bus'
Local IntentObserved BusResult
00Continue
11Continue
10Arbitration lost

On loss:

  • Set Arbitration_Lost.
  • Release SDA and SCL.
  • Stop participating.
  • Do not generate STOP.

I²C Implementation Steps

  1. Build the two 3-input open-drain bus resolvers for SDA and SCL.
  2. Register previous SDA and SCL values and decode START, STOP, and SCL rising edges.
  3. Track the active transaction and count eight SCL rising edges.
  4. Generate the ninth-clock ACK_Window, ACK_Sample, ACK_Detect, and NACK_Detect signals.
  5. Use the SDA ownership MUX to select TX_Bit or ACK_Release.
  6. In a larger controller, shift the address/data, observe SCL_Bus for stretching, and compare intended SDA with the resolved bus for arbitration.

5. CAN and CAN FD Hardware Design

Controller Area Network (CAN) Overview

Controller Area Network (CAN) is a message-based serial interface for a shared bus.

Frame identifiers select the message and take part in arbitration.

CAN Controller and Transceiver

CAN Controller and Transreceiver

The controller handles the digital protocol.

The transceiver connects it to the physical bus.

Dominant and Recessive Bits

BitNameMeaning
0DominantForces the resolved bus LOW
1RecessiveReleases the bus

A dominant bit wins when nodes transmit different values.

BUS_BIT = Node0_TX · Node1_TX · ...

CAN Arbitration Hardware

The controller compares TX_BIT with BUS_BIT during the arbitration field.

ARB_LOST_Detect =
Arbitration_Enable · TX_BIT · BUS_BIT'

The learning circuit implements this expression with one native 3-input AND gate and a bubbled BUS_BIT input. It is a combinational detector only: it does not latch the event, stop the transmitter, or implement retry and fault-state behavior.

TX_BITBUS_BITResult
00Continue
11Continue
10Arbitration lost

On loss, the node stops transmitting for that attempt.

It continues observing the winning frame.

Important: Arbitration loss is not a frame error.

Learning-oriented CAN arbitration-loss detector implemented as a three-input AND of Arbitration_Enable, TX_BIT, and inverted BUS_BIT, producing ARB_LOST_Detect only for a recessive-to-dominant mismatch.

Direct-I/O simplification: Arbitration_Enable, TX_BIT, and BUS_BIT are direct inputs. In a complete CAN node, they come from the protocol controller and the observed transceiver/bus path; ARB_LOST_Detect then feeds the controller's arbitration state logic.

CAN Bit Timing

Timing PartFunction
Time quantumBasic timing step
Timing segmentsDivide one bit time
Sample pointCaptures BUS_BIT
SynchronizationAligns local timing to bus edges
ResynchronizationApplies a limited timing correction

CAN Bit-Stuffing Sequence

CAN Bit Stuffing

The transmitter inserts one complementary bit after five equal bits.

The inserted bit does not advance the original frame counter.

The receiver removes a valid stuff bit.

It asserts STUFF_ERROR when the complement is missing.

CAN Errors and Fault States

ErrorShort Meaning
Bit errorTX and bus differ unexpectedly
Stuff errorExpected complement is missing
CRC errorCRC comparison fails
Form errorFixed field has an illegal value
ACK errorRequired acknowledge is missing
Fault StateMeaning
Error ActiveNormal error signalling allowed
Error PassiveRestricted error signalling
Bus-OffNode stops bus participation

The counter rules and thresholds depend on the controller specification.

CAN Acceptance Filter

Accept = (RX_ID · MASK) == (FILTER_ID · MASK)

Accept = 1 stores the valid received frame.

Controller Area Network with Flexible Data Rate (CAN FD)

CAN FD means Controller Area Network with Flexible Data Rate.

FeatureCAN FD Change
PayloadLarger data field
Data phaseOptional faster bit rate
Bit-rate switchingSelects the faster data phase
Frame controlAdditional control differences

CAN Implementation Steps

  1. Build the local bit-time counter and sample event.
  2. Generate the original frame-bit stream.
  3. Add dominant/recessive bus resolution.
  4. Compare TX_BIT with BUS_BIT during arbitration.
  5. Stop TX participation after ARB_LOST_Detect.
  6. Add the run counter and stuff-bit selector.
  7. Add receive de-stuffing and error checks.
  8. Apply the acceptance filter before RX storage.
  9. Store error and fault-state status.

6. Serial Interface Integration, Buffering and Reliability

Status-Signal Behavior

TypeBehaviorExamples
LevelActive while the condition existsBusy, buffer full
PulseActive for one CLK_SYS cycleDone, event pulse
StickyHeld until clearedError, Overrun, Timeout

Buffer Selection

BufferUse
Single registerOne word at a time
Double bufferTransfer one word while preparing another
FIFOStore bursts or rate mismatch

TX and RX Data Protection

RiskRequired Protection
Active TX word overwrittenLock it or use a separate buffer
Unread RX word overwrittenPreserve it and set Overrun
RX buffer fullSet Overflow or apply backpressure

Clock-Domain Crossing Reuse

Transfer TypeReused Structure
Single asynchronous bitSynchronizer
Controlled multi-bit valueStable-data handshake
Continuous streamAsynchronous FIFO

Configuration Update Protection

Do not change active protocol settings during a transaction.

PolicyAction
Idle-only writeReject changes while Busy = 1
Deferred updateApply after completion
Shadow and commitCopy settings at a safe boundary

Protected settings include:

  • UART baud divider
  • SPI CPOL and CPHA
  • I²C address
  • CAN acceptance filter

Timeout and Safe Abort

Timeout and Safe Abort

The abort action must not create an illegal bus event.

Reset and Idle Outputs

InterfaceIdle Output
UARTTX = 1
SPICS_n = 1, SCK = CPOL
I²CSDA and SCL released
CANRecessive, released, or TX disabled

Interface Selection

RequirementInterface
Point-to-point link without clockUART
Full-duplex peripheral linkSPI
Addressed two-wire busI²C
Multi-node bus with arbitrationCAN or CAN FD

Integrated Serial Interface Hardware

Integrated Serial Interface Hardware

The protocol engine controls bit-level operation.

The buffers and status logic connect it safely to the surrounding system.

Select Answer

Restart quiz!