I2C Memory vs. Register Access: Understanding the Difference

The I2C protocol requires writing the register address before reading its content from a slave device. Reading register content without prior address writing violates the I2C protocol.

To read the content of a specific register from a slave device, a write operation to the slave device with the target register address must precede the read operation.

The steps to read the content of a slave device register in the I2C protocol are as follows:

START -> 7-bit Slave Address -> R/W=0 (Write Operation) -> ACK -> Register Address (1 byte) -> ACK -> Sr (Restart) -> 7-bit Slave Address -> R/W=1 (Read Operation) -> ACK -> Data from Register -> NACK (from slave as it has no more data to send) -> STOP.

Refer to Texas Instruments’ “Understanding the I2C Bus” document for a comprehensive understanding of the I2C protocol: Understanding the I2C Bus

The readReg function is designed to read 2 bytes from the slave. Verify if the size has been changed to 1 byte if intending to read only 1 byte.

Reg0 is often the EN/RESET register. Verify the operations performed before reading Reg0, such as whether data has been written to this register.

Try accessing the content of a different register, for example, Reg4, to verify if the written content can be read back.

Example of accessing register address 0x05 to read the raw temperature byte from the MCP9808 temperature sensor on RA6M4: First, perform a write operation, writing to slave 0x05, which is the address of the register to be read. Then, after approximately 100ms (due to some timeout while loops), the process will read the content from this register.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *