TECHNOLOGY

Linux I2C register reads: separate write and read calls are not a combined transfer

In this article
THE QUICK TAKE

Use the sensor’s documented transaction shape and verify adapter support; two successful system calls do not prove the bus supplied the required no-stop boundary.

The register selector and read have the wrong boundary

An edge application selects a sensor register with a write call, then reads bytes for its classifier. The peripheral’s documented protocol requires a combined operation without an intervening STOP, but the application assumes adjacent system calls provide that shape. Both calls can look successful without establishing the intended bus contract. Verify the selected sensor’s requirements before investigating normalization or model quality. Not every sensor needs the same transaction, so the device protocol must supply the premise rather than a generic register-reading recipe.

Plain calls cannot express every I2C transaction

The Linux userspace I2C guide explicitly says plain read and write calls cannot express combined read/write transactions. It documents I2C_RDWR for a combined transfer without a STOP between messages, conditional on I2C_FUNC_I2C support. Preserve the adapter’s advertised functionality and the exact operation chosen. An opened bus device does not establish that every desired message shape is supported, and an SMBus helper has its own protocol contract rather than being a universal substitute for arbitrary I2C operations.

Each combined message carries its own addressing

The userspace ABI header defines the message-array interface and combined transfer boundary. The guide explains that address and direction belong to individual messages, with message addressing overriding earlier interface settings. Review those fields together with buffer length and register encoding. A correct no-stop sequence aimed at the wrong address is still wrong. Keep register-byte order and returned-value decoding under the peripheral’s specification instead of assuming the bus transaction automatically establishes a native integer representation.

Bus continuity is not a sampling snapshot

A combined transfer supplies a bus-level boundary; it does not universally latch every changing sensor register into one simultaneous observation. The device may define its own snapshot, ready flag or read-order rule. Establish that contract separately when several fields form one model input. Also preserve acquisition errors instead of filling failed reads with ordinary zeros that look like valid measurements. A retry can obtain a newer observation, so record its identity rather than silently combining successful fields from different acquisition attempts.

Propose a protocol-aware transfer fixture

Use a harmless simulated peripheral or an approved disposable target with a known register contract. Compare the intended combined operation with separate calls, inspect message boundaries through the supported diagnostic path and verify known returned values. Include unsupported adapter capability, wrong addressing and acquisition failure. Acceptance requires the correct transaction and source-consistent data, not only a successful syscall. No I2C adapter was opened, registers written or hardware probed here; the fixture defines correctness evidence without inventing transfer timing or a device-specific guarantee.

Validate acquisition before evaluating inference

Embedded pipeline boundaries keep I/O distinct from arithmetic. Binary tensor framing keeps payload interpretation distinct from transport success. Linux I2C adds a transaction-shape prerequisite for the chosen sensor. Retain adapter capability, message sequence, peripheral protocol and acquisition outcome with the resulting features. This makes a model-input defect diagnosable without claiming that any register read is a combined transfer or that combined transfer alone guarantees a coherent physical sample.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles