Sensors & Measurement · Study deck

Sensor Interfacing Protocols

Picture a room sensor connected to a small controller.

Gateway Gus is your guide for this deck.

sensorinterfacingprotocols
Gateway Gus, the assigned guide for sensor bus protocols and diagnostics.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Differentiate between I2C, SPI, and UART communication protocols based on wiring, speed, and topology
  • Configure an I2C bus with correct pull-up resistors and address assignments for multi-sensor applications
  • Implement SPI communication with proper mode selection for high-speed sensor data transfer
  • Evaluate and justify the appropriate protocol for specific sensor requirements and constraints
iotclass.org

Major section

Start With the Measurement Story

The sensor may use one pin, two shared wires, a clocked link, or a simple serial line.

  • The best choice is the one that keeps the reading and its failure state clear.
  • A protocol means shared rules for an exchange.
  • GPIO means general purpose input and output pins.
  • Silence must not become a valid zero.
iotclass.org

Major section

Start With the Measurement Story (continued)

Inter-integrated circuit (I2C) means a short shared wired link between chips.

  • Serial Peripheral Interface (SPI) means a clocked wired link with separate data paths.
  • Universal asynchronous receiver-transmitter (UART) means a serial link that agrees on timing without a shared clock.
  • This runway does not prove cable length, noise margin, or power use.
iotclass.org

Major section

In 60 Seconds

The capacitance and current limits leave no valid passive pull-up at the stated bus load.

  • At 400 pF, 4.7 kΩ rises in about 1.59 µs, slower than the 1 µs Standard-mode limit.
  • Fast mode needs R ≤885 Ω for rise time and ≥967 Ω for sink current.
  • No passive value meets both bounds at that capacitance; reduce capacitance or redesign.
At 400 pF, a 4.7 kΩ pull-up rises in about 1.59 µs, slower than the 1 µs Standard-mode limit. Under the chapter's 3.3 V, 3 mA Fast-mode assumptions, R must be ≤885 Ω for rise time and ≥967 Ω for sink current: no passive value meets both. Reduce capacitance or redesign.
iotclass.org

Major section

I2C Communication Protocol

The controller addresses the sensor for writing, selects a register, issues a repeated START, addresses it for reading, accepts the returned byte, and ends the transfer with NACK and STOP.

  • The repeated START preserves one logical transaction while reversing direction; this sequence is the protocol meaning behind the API calls used later.

Key terms

I2C (Inter-Integrated Circuit)
I2C (Inter-Integrated Circuit) is a two-wire synchronous protocol perfect for connecting multiple sensors using minimal GPIO pins.

Why it matters

That shared electrical boundary explains why duplicate addresses, excessive bus capacitance, or missing pull-ups can defeat an otherwise correct transaction sequence.

I2C Protocol Sequence: Reading Temperature from BMP280 Sensor
I2C Protocol Sequence: Reading Temperature from BMP280 Sensor
iotclass.org

Major section

SPI Communication Protocol

SPI (Serial Peripheral Interface) is a synchronous, full-duplex communication protocol using four lines: MISO (Master In Slave Out), MOSI (Master Out Slave In), SCK (Serial Clock), and CS (Chip Select).

  • Unlike I2C, SPI supports simultaneous bidirectional data transfer.
  • The transaction is easiest to understand when chip selection and clocking are separated from the two data paths.
SPI Protocol Communication: Full-Duplex SD Card Read Transaction
SPI Protocol Communication: Full-Duplex SD Card Read Transaction
iotclass.org

Major section

UART Serial Communication

A direct TX/RX link commonly connects two devices, but a multidrop physical layer and an addressing protocol can connect more.

  • Both sides of each link must use compatible baud and frame settings.
  • Asynchronous: No shared clock; endpoints need compatible baud rates.
  • Many sensors provide UART as a simpler alternative to I2C/SPI, though at lower data rates.

Key terms

UART
UART is commonly used for GPS modules (NMEA sentences at 9600 bps), Bluetooth modules (HC-05 AT commands), GSM/cellular modems, and debug/logging output.
iotclass.org

Deck summary

Key takeaways

The sensor may use one pin, two shared wires, a clocked link, or a simple serial line.

  • Inter-integrated circuit (I2C) means a short shared wired link between chips.
  • Sensor communication protocols (I2C, SPI, UART) are the "languages" sensors and microcontrollers use to exchange data.
  • The controller addresses the sensor for writing, selects a register, issues a repeated START, addresses it for reading, accepts the returned byte, and ends the transfer with NACK and STOP.
  • SPI (Serial Peripheral Interface) is a synchronous, full-duplex communication protocol using four lines: MISO (Master In Slave Out), MOSI (Master Out Slave In), SCK (Serial Clock), and CS (Chip Select).
iotclass.org

Retrieval practice

Recall check 1 of 4

Gateway Gus says: answer from memory, then check your reasoning.

Q1Per Phoebe's Field Notes, why can't a 4.7 kOhm pull-up reliably run an I2C bus at the full 400 pF capacitance ceiling, even at just 100 kHz (Standard mode)?

AAt 4.7 kΩ and 400 pF, rise time is about 1.59 µs, above the 1 µs Standard-mode limit.
BAt 400 pF, any 4.7 kΩ pull-up is safe because the bus meets its capacitance limit.
CAt 4.7 kΩ, pull-up resistance exceeds a fixed I2C maximum for every bus load.
DAt 100 kHz, Standard mode has no rise-time limit to constrain the pull-up.
Show answer

Answer: A see answers page

iotclass.org

Retrieval practice

Recall check 2 of 4

Gateway Gus says: answer from memory, then check your reasoning.

Q2In the I2C protocol, what does Wire.endTransmission(false) do differently from Wire.endTransmission(true)?

AIt halves the I2C bus clock rate for the next read transaction.
BIt turns off both internal SDA and SCL pull-up resistors.
CIt omits STOP so the next transaction can use a Repeated START.
DIt turns a write transaction into a broadcast to every I2C device.
Show answer

Answer: C Passing false to endTransmission() sends a Repeated START instead of a STOP.

iotclass.org

Retrieval practice

Recall check 3 of 4

Gateway Gus says: answer from memory, then check your reasoning.

Q3Per this chapter's 'When to Choose Each Protocol' guidance, which requirement is listed as a reason to choose SPI over I2C?

AA sub-millisecond response for real-time data transfer.
BA shortage of GPIO pins for a shared sensor bus.
CA moderate transfer rate below roughly 50 kB/s.
DA group of low-rate sensors sharing one bus.
Show answer

Answer: A The chapter lists real-time transfer under 1 ms as a reason to investigate SPI; verify the installed end-to-end timing.

iotclass.org

Retrieval practice

Recall check 4 of 4

Gateway Gus says: answer from memory, then check your reasoning.

Q4Why does a basic direct TX/RX UART link usually connect two devices, while a multidrop UART network needs extra design?

AUART lacks addressing and arbitration; multidrop needs transceivers and turn-taking.
BUART baud rate inherently caps every link at two communicating devices.
CUART requires a dedicated chip-select wire per device, as SPI does.
DUART devices share one fixed hardware address, so a third collides.
Show answer

Answer: A Basic UART frames carry data and framing bits but no inherent device address.

iotclass.org

Print reference

Answers

Answer key.

  1. A · The chapter's own worked case: R=4.7kOhm, C=400pF gives tau=RC=1.88us and tr=0.847xRC=1.59us -- slower than the 1000ns Standard-mode rise-time limit, so a bus that actually reaches the 400pF ceiling cannot run reliably at 4.7kOhm even at 100kHz. This is why fast, heavily-loaded buses use smaller pull-ups (1-2.2kOhm) instead.
  2. C · Passing false to endTransmission() sends a Repeated START instead of a STOP.
  3. A · The chapter lists real-time transfer under 1 ms as a reason to investigate SPI; verify the installed end-to-end timing.
  4. A · Basic UART frames carry data and framing bits but no inherent device address.
iotclass.org
With the answer frame visible, connect each fault to its test. The pull-up and capacitance set I-squared-C rise time. A repeated start keeps a register read in one transaction. S-P-I is a candidate for some fast transfers, subject to measured timing. More than two U-A-R-T endpoints need added electrical and addressing rules. None of these exchanges proves a sensor reading is calibrated.