rust-embedded / embedded-hal

A Hardware Abstraction Layer (HAL) for embedded systems
Apache License 2.0
2.01k stars 202 forks source link

Clarification Needed for I2C Transaction Contract #621

Closed nhpupu closed 3 months ago

nhpupu commented 3 months ago

Issue Description

The I2C trait's transaction contract in embedded-hal currently states:

If the last operation is a Read the master does not send an acknowledge for the last byte.

This statement is ambiguous and doesn't accurately reflect I2C protocol requirements, potentially leading to implementation errors.

Proposed Clarification

The contract should specify that a NACK (No Acknowledge) must be sent at the end of every read operation within a transaction, not just the final one that is followed by a stop condition. This includes read operations that are followed by a repeated start condition.

Rationale

In I2C protocol, a master must signal the end of a read operation by sending a NACK after the last byte it wishes to receive. This NACK is crucial because:

  1. It informs the slave to stop sending data and release the SDA (data) line.
  2. It allows the master to regain control of the SDA line, necessary for generating either a stop condition or a repeated start condition.

Without a NACK, the slave might continue holding the SDA line low, preventing the master from properly terminating the current operation or initiating the next one.