Skip to content

tests: Periph I2C Flags #53

@gschorcht

Description

@gschorcht

While analyzing why the following tests in tests/periph_i2c/tests/04__periph_i2c_flags fail for esp32-wroom-32

  • Repeated Start Read Bytes 0 Should Succeed

    Repeated Start Read Bytes 0 Should Succeed
    [Documentation] Verify DUT does not lockup on repeated start read
    PHiLIP.write reg user_reg 0
    API Call Should Succeed I2C Read Bytes leng=2 flag=${I2C_FLAG_NOSTOP}
    API Call Should Error I2C Read Bytes leng=2
    API Call Should Succeed I2C Read Bytes leng=2 flag=${I2C_FLAG_NOSTART}

  • Repeated Start Read Bytes 0xFF Should Succeed

    Repeated Start Read Bytes 0xFF Should Succeed
    [Documentation] Verify DUT does not lockup on repeated start read
    PHiLIP.write reg user_reg 255
    API Call Should Succeed I2C Read Bytes leng=2 flag=${I2C_FLAG_NOSTOP}
    API Call Should Error I2C Read Bytes leng=2
    API Call Should Succeed I2C Read Bytes leng=2 flag=${I2C_FLAG_NOSTART}

I was wondering why the second i2c_read_bytes call should fail?

In section 3.1.10, the I2C standard only specifies:

"A data transfer is always terminated by a STOP condition (P) generated by the master. However, if a master still wishes to communicate on the bus, it can generate a repeated START condition (Sr) and address another slave without first generating a STOP condition. Various combinations of read/write formats are then possible within such a transfer."

From my point of view, "address another slave ..." doesn't mean necessarily that a second read with the same slave address should fail. It just says, that the master can continue the communication on the bus with another slave. In fact, the slave address in combined format is the same and only the direction is changed. Furthermore, "Various combinations ..." does not imply that the combined read after write transfer must be the only one.

Furthermore, according to Note 4 in section 3.1.10

"I2C-bus compatible devices must reset their bus logic on receipt of a START or repeated START condition such that they all anticipate the sending of a slave address"

That is, all slaves including the former one should await an address field after a repeated start. So why shouldn't it be the same address as before?

Although it might not make sense to have consecutive read transfers from the same slave, the standard does not forbid this.

I have tested it with a chip PCF8575 chip from NXP, the owner of the I2C standard. The chip accepts consecutive i2c_read_bytes calls with repeated START conditions. So IMHO, the ESP32 I2C behaves correctly.

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions