Skip to content

i2c slave .onReceive() failure/error when 'restart' rather than 'stop' is transmitted by i2c master #585

@DWiskow

Description

@DWiskow

wire.cpp does not generate a "Wire.onReceive()" interrupt for an i2c Slave following transmission of a 'restart' rather than a 'stop' by an i2c Master. This situation can occur frequently when a Master sends a register address followed by a read request for the contents of that register.

This is particularly important in a Multi Master i2c system, where the Master should not allow another Master to obtain control of the bus between its write of the required register and the read of the register content [and therefore explicitly uses a 'restart' rather than a 'stop' follow by a 'start' between it's write and read over the bus].

I have written a short Arduino C++ program to illustrate the issue
i2cmemory.ino.txt

The error is that wire.cpp in arduino-pico/libraries/Wire/src only checks the IC_INTR_STAT register bit 10 (R_START_DET - a 'start' condition) to generate it's interrupt . . . it should also check and act on bit 12 (R_RESTART_DET - i.e. a 'restart' condition)

The attached image shows the required changes to wire.cpp to correct this wire cpp diff

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions