🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

SPI and I2C Protocols: Timing and Practical Use

Embedded SystemsSerial CommunicationđŸŸĸ Free Lesson

SPI and I2C Protocols: Timing and Practical Use

What You'll Learn

  • 1Configure SPI mode and clock parameters
  • 2Address I2C devices and manage acknowledgements
  • 3Diagnose bus hangs and perform recovery
  • 4Choose SPI or I2C for a given peripheral

SPI and I2C cover most chip to chip needs on a board. SPI is fast, full duplex, and simple, but every device needs its own chip select line and the timing rules are configured manually. I2C uses two wires with addresses and acknowledgements, which scales to many devices at lower speed. Both protocols fail in characteristic ways: SPI mode mismatches corrupt data, while I2C devices can wedge the bus and need an explicit recovery sequence.

SPI Modes and Timing

SPI configures clock polarity and clock phase into four modes that decide when data is sampled relative to the clock edge. Bit order, clock frequency, and frame length must match the peripheral datasheet, and the chip select line must be asserted before the first clock edge and held through the last.

Signal integrity sets the practical maximum speed: long traces, heavy capacitance, and poor ground return round off edges. Reading a device while another shares the same bus requires tri state outputs so two drivers never fight.

I2C Addressing and Transfers

I2C devices appear at seven bit addresses and the bus uses start and stop conditions plus an acknowledge bit after every byte. A typical transfer writes a register pointer then reads data with a repeated start, which keeps the transaction atomic for the device.

Pull up resistors set rise time against bus capacitance; too weak a value fails rise time specs, too strong wastes current and may exceed sink limits. Clock stretching lets a slow device hold the clock low between bytes.

Bus Hangs and Recovery

A device interrupted mid transfer can hold the data line low forever, blocking everyone. Recovery clocks the data line high for nine pulses while the master generates clock edges manually, then issues a stop condition to free the bus.

Designs also add buffers for long buses, separate domains with level shifters, and a power on check that verifies each expected address acknowledges before normal operation begins. Those checks turn a silent wiring fault into a clear diagnostic message during start up instead of a mystery later in the field.

SPI and I2C Compared

AspectSPII2C
WiresClock, data in, data out, selectSerial data and clock
SpeedTens of megahertz typical100 kilohertz to 3.4 megahertz
AddressingChip select line per deviceSeven bit address per device
FlowNo acknowledgementAcknowledge after each byte
Best fitDisplays, flash, ADCsSensors, EEPROMs, PMICs

Real-World Examples

  • Flash memory read — Chip select low, mode 0 clock, command and address bytes, then data clocked back in a burst.
  • Sensor register read — Write register pointer with a repeated start, then read bytes with acknowledgements from the sensor.
  • Multiple sensors on one bus — Three devices at distinct addresses share the two wires with one shared pull up pair.
  • Bus recovery sequence — Nine clock pulses plus a stop condition release a slave that stalled mid byte after a reset.

âš ī¸Match SPI Mode Exactly

Wrong clock polarity or phase samples data on the wrong edge, which shows up as consistent bit errors at low speed and total failure at high speed.

Common Mistakes

Oversized I2C pull-ups

Fix: Strong pull-ups exceed slave sink current and slow edges; calculate from bus capacitance.

Forgetting shared bus tri-state

Fix: Two devices driving the same data line corrupt each other without proper chip select discipline.

Ignoring clock stretching

Fix: Blocking reads from a stretching slave will time out if the driver assumes a fixed clock.

Key Takeaways

  • SPI mode, bit order, and chip select discipline define correctness.
  • I2C adds addressing and acknowledgement on just two wires.
  • Pull-up sizing and capacitance set practical I2C limits.
  • Recovery sequences restore a wedged bus without a power cycle.

Frequently Asked Questions

Why does my SPI device respond only at low speed?

Signal integrity limits usually appear first at high clock rates; shorten traces, improve ground return, and check mode settings.

What happens if two I2C devices share an address?

Both acknowledge, corrupting data; use address pins, a multiplexer, or a different part.

Do I2C buses need a common ground?

Yes, and they also need pull-ups on the segment that matches the logic level of the devices.

Interview Questions

Q1: How do you recover an I2C bus stuck low?

Toggle the data line manually nine times while generating clock pulses, then send a stop condition, and verify the bus idles high.

Q2: When would you choose SPI over I2C?

When throughput matters, transfer length is long, or you need full duplex, and you have enough pins for chip selects.


Extended Learning: Beyond the Basics

Key Concepts Summary

This lesson covers fundamental concepts that serve as building blocks for more advanced topics. Master these basics before moving to intermediate and advanced material.

Prerequisite Knowledge

Before studying this topic in depth, ensure you understand:

  • Basic definitions and terminology
  • Core formulas and their derivations
  • Common applications in real-world scenarios
  • Typical pitfalls and misconceptions

Step-by-Step Walkthrough

Let us work through a complete example to solidify understanding:

Step 1: Identify the problem type. Determine which category this problem falls into and which approach is most appropriate.

Step 2: Apply the relevant formula. Substitute known values into the appropriate equation, paying attention to units and constraints.

Step 3: Simplify and solve. Work through the algebra step by step, checking each intermediate result.

Step 4: Verify the answer. Check that the solution satisfies the original conditions and makes logical sense.

Common Mistakes to Avoid

  1. Misidentifying the problem type — Always start by categorizing the problem
  2. Incorrect formula application — Verify the formula applies to your specific case
  3. Unit errors — Always check units are consistent throughout
  4. Sign errors — Pay careful attention to positive and negative values
  5. Rounding too early — Keep full precision until the final answer
  6. Forgetting constraints — Check that solutions satisfy all given conditions

Real-World Applications

Understanding this concept is essential for:

  • Advanced problem solving in examinations
  • Building intuition for more complex topics
  • Developing analytical thinking skills
  • Applying mathematical reasoning to practical situations

Practice Exercises

  1. Basic: Solve 5 problems of increasing difficulty using the core concept.
  2. Intermediate: Apply the concept to word problems with multiple steps.
  3. Advanced: Combine this concept with 2-3 other topics in a comprehensive problem.
  4. Challenge: Create your own problem that requires this concept plus additional knowledge.

Interview and Exam Tips

  • Common question patterns: Identify which exam or interview formats test this topic
  • Time management: Practice completing problems within time constraints
  • Common traps: Know the typical mistakes examiners set as distractors
  • Verification strategy: Develop a quick method to check your answer

Related Topics

Quick Reference Card

ConceptFormula/RuleKey InsightCommon Use
Core DefinitionSee main textUnderstand the intuitionFoundation for all applications
Key FormulaSee main textMemorize the derivationDirect problem solving
Special CaseSee main textRecognize when it appliesSimplifies complex problems
Edge CaseSee main textKnow the limitationsAvoids errors

Further Reading

For students who want to go deeper:

  • Standard textbooks on the subject
  • Research papers applying this concept
  • Online courses with video explanations
  • Practice problem collections with detailed solutions
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-11-14

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Embedded Systems Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement