Linux I2C and SPI Device Driver Development in Embedded Linux Systems

Linux I2C and SPI Device Driver Development in Embedded Linux Systems

If you’re working with embedded Linux systems, sooner or later you’ll face one real challenge –  how to make your hardware talk to the Linux kernel properly. This is where Linux I2C and SPI device driver development comes in. Whether it’s a temperature sensor, EEPROM, display, or communication module, most peripherals rely on I2C and SPI communication in embedded systems. And without a proper driver, even the best hardware is useless. In this guide, we’ll break things down in a practical, no-nonsense way so you actually understand:

  • How I2C device driver in Linux works
  • How to build an SPI device driver in Linux
  • Role of device tree in embedded Linux
  • Real-world use cases engineers deal with daily

What is I2C and SPI in Embedded Linux?

I2C and SPI are serial communication protocols used in embedded Linux systems to connect peripherals like sensors, memory devices, and displays to the processor.

Difference Between I2C and SPI

I2C uses two wires and supports multiple devices, while SPI uses four wires and provides faster communication.

What is a Device Driver in Embedded Linux?

Think of a device driver as a translator. Your hardware speaks electrical signals. Your OS speaks software instructions. The driver connects both worlds. In embedded Linux driver development, drivers handle:

  • Hardware initialization
  • Data transfer
  • Interrupts
  • Resource management

The Linux kernel device drivers are structured into subsystems — and for us, the most important are:

  • I2C subsystem in Linux kernel
  • SPI subsystem in Linux kernel

 

Start Your Training Journey Today

 

I2C Communication in Embedded Systems (Simple Explanation)

I2C is used when:

  • Speed is not critical
  • You want fewer pins
  • Multiple devices share the same bus

Only two wires:

  • SDA → Data
  • SCL → Clock

That’s why it’s everywhere in:

  • Sensors
  • RTC modules
  • EEPROMs

Why Engineers Prefer I2C

  • Saves PCB space
  • Easy to scale
  • Address-based communication

How Linux Handles I2C (Behind the Scenes)

The Linux kernel I2C framework is designed so you don’t have to deal with raw signals.

It has 3 layers:

  • Adapter driver (hardware controller)
  • Core framework
  • Client driver (your device driver)

How it actually works:

  • Device defined in device tree configuration for I2C devices
  • Kernel matches compatible string
  • Calls probe function
  • Driver starts communication

How to Write I2C Device Driver in Linux

Let’s keep it practical.  Every Linux I2C driver example follows this structure:

  • Driver registration
  • Probe function
  • Remove function
  • Read/write logic

Important APIs

  • i2c_smbus_read_byte()
  • i2c_smbus_write_byte()
  • i2c_transfer()

Real-world tip:

Most beginners fail not in code — but in device tree mismatch.

 

Explore Courses - Learn More

 

SPI Communication in Embedded Systems

Now, when speed matters → SPI wins.

Unlike I2C, SPI uses:

  • MOSI
  • MISO
  • SCLK
  • CS

Why SPI is Powerful

  • Faster than I2C
  • Full-duplex communication
  • More reliable timing

Used in:

  • Displays
  • Flash memory
  • ADC/DAC
  • RF modules

SPI Subsystem in Linux Kernel

Similar to I2C, the Linux SPI core framework abstracts hardware.

Structure:

  • SPI master driver
  • SPI core
  • SPI device driver

How to Develop SPI Driver in Embedded Linux

A basic SPI driver example in Linux kernel includes:

  • Driver struct
  • Probe/remove functions
  • Data transfer using SPI APIs

Important APIs

  • spi_sync()
  • spi_write()
  • spi_read()

Pro insight:

SPI debugging is easier than I2C because signals are independent — use logic analyzer.

I2C vs SPI in Embedded Systems (Engineer’s View)

FeatureI2CSPI
SpeedLowHigh
Pins24
DebuggingHardEasy
Use CaseSensorsDisplays/Flash

Real decision rule:

  • Use I2C → low-speed + multiple devices
  • Use SPI → high-speed + real-time

Device Tree in Embedded Linux (Most Important Part)

If your driver isn’t loading, 90% of the time the issue is here.

The device tree in embedded Linux defines:

  • Bus
  • Address / Chip select
  • Compatible driver

Why it matters:

Without correct device tree → driver won’t probe

Real Applications (Where This Is Used)

IoT

  • Smart sensors
  • Wearables

Industrial Embedded Systems

  • Automation controllers
  • Monitoring devices

Automotive

  • ECU communication
  • Dashboard electronics

 

Conclusion

If you want to become a strong embedded engineer, mastering Linux I2C and SPI device driver development is not optional — it’s essential.

Once you understand:

  • Linux kernel frameworks
  • Device tree configuration
  • Driver lifecycle

You can build real-world embedded Linux systems used in industry.

 

Talk to Academic Advisor

Frequently Asked Questions

It is a software module that allows Linux to communicate with I2C-based hardware devices.

By registering a SPI driver, implementing probe/remove functions, and using SPI APIs for communication.

A configuration file that describes hardware and enables automatic driver loading.

Author

Embedded Systems trainer – IIES

Updated On: 10-04-26


10+ years of hands-on experience delivering practical training in Embedded Systems and it's design