Skip to content

Wire.requestFrom() with zero bytes reads many bytes. #421

Open
@Koepel

Description

@Koepel

If zero number of bytes are requested from any existing device on the I2C bus with Wire.requestFrom( i2c_address, 0); then the acknowledge from that device makes the Wire library read 37 bytes.
The return value of Wire.requestFrom( i2c_address, 0); is zero.

Request zero bytes:

Wire.requestFrom( 0x77, 0);  // 0x77 does exist

Result:
afbeelding

As far as I can tell, the data is real data from the sensor. There is also a NACK after the last data byte just before the STOP condition. Everything is according to a standard I2C session, except that 37 bytes don't fit in a 32 byte buffer and there should be no reading of data at all.

If the device does not exist, then the NACK will stop the I2C session.
afbeelding

Background

The "I2C Scanner" sketch uses a 'write' command with zero bytes to check the acknowledge. There are however some capacitive touch sensors that don't have the hardware for the 'write' command. They do acknowledge to the 'read' command.
Therefor I was testing a "I2C Read Scanner" and was comparing the behavior of the AVR Wire library against the SoftwareWire library with requestFrom( i2c_address, 0); in the Wokwi simulator with a simulated logic analyzer. The Arduino Uno with DS1307 (in Wokwi) issued this bug.
I confirmed this with real hardware with a Arduino Mega 2560 and a BMP085 and also a Arduino Uno as a Slave.
The screendumps above are with real hardware and a LHT00SU1 logic analyzer with PulseView/sigrok.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions