I2C fault injection

When writing drivers for a new I2C host controller, it is important to not only get the normal operation working, but to implement robust error handling and recovery. This requires a way to force certain conditions that a “normal” I2C slave device will not exhibit.

There is a I2C fault injection/testing framework for Linux, which runs on devices with a supported I2C slave peripheral:


This provided some good ideas on what kinds of errors should be tested. However, I had no supported hardware at hand, and I wanted something small that can be easily attached to a board under development.

Looking for suitable I2C slave hardware, I settled on an ATmega88/328. Its I2C block handles the low-level protocol including clock stretching, and leaves enough of the higher-level protocol to the firmware to get decent control about what happens during a complete transaction. It has an address mask register which enables it to respond to multiple I2C addresses – this makes it easy to trigger different behaviours by accessing different target addresses.

The first prototype simply used an ATmega328 breakout board, but I also made a small PCB.

The firmware implements the following functions:

Full project details are available at


2021-07-02 by rincewind