I2C Slave Read Operation - Page 1
Forum section: electronics / general

author: Mtech1
author_rank: Contributor
timestamp: October 16, 2023, 11:48:47 am
content: Hi,I'm not sure about how a slave read operation is done in I2C communication, so I'll explain the steps, what I understandso far from documents but please correct me if I'm wrong.I2C is a communication protocol designed to exchange data between multiple masters and multiple slaves on the same bus.Slave Write Operation:1. The master generates a start condition.2. The master sends the slave address with write mode.3. If the slave accepts the address, it sends an acknowledgement signal to the master.4. The master can then send the data, which could be the internal register address of the slave device. If the slave accepts the byte, it sends an acknowledgment to the master.5. If the master doesn't want to continue sending data, it generates a stop condition.6. If the slave doesn't accept the data from the master, it sends a not-acknowledgment signal, and the master terminates communication by generating a stop condition.Slave Read Operation:1. The master generates the start condition.2. The master sends the slave address in read mode.3. If the slave accepts the address, it sends an acknowledgment signal to the master.4. The master can then send the internal address of the register from which it wants to read data. If the slave accepts the register address, it starts sending the data stored at that address to the master. Master accept data it send acknowledgement to slave5. If the master wants to read data from another register, it can send the address of that register. If the slave accepts it, it will send the data from the register to the master.6. If the master doesn't want to read more data, it generates a stop condition to terminate the communication.

author: woofy
author_rank: Frequent Contributor
timestamp: October 16, 2023, 12:02:01 pm
content: Quote from: Mtech1 on October 16, 2023, 11:48:47 amNo, its not like that.1. The master generates the start condition.2. The master sends the slave address in write mode.3. The master sends the internal address of the register from which it wants to read data.4. The master generates a restart condition.5. The master sends the slave address again, this time in read mode.6. The master reads as much data as required.7. The master generates a stop condition.

author: Mtech1
author_rank: Contributor
timestamp: October 17, 2023, 10:49:14 am
content: Thank you for your patience. To make sure I address correctly, let's use an example for clarification.Let's consider a specific example to illustrate an I2C transaction. We have a slave device with the address 0xD0 in write mode and 0xD1 in read mode. This slave has an internal register with the address 0x01, which we want to read from or write to.In a combined read and write transaction where both operations happen in one transaction:1.Start Condition: The transaction begins with a start condition.2.Address Phase (Write): The master sends the slave address (0xD0) with the write bit (0) to initiate the write operation. The slave receives this address and sends an acknowledgment (ACK) to confirm.3.Register Address: The master sends the internal register address (0x01) to specify where the data should be written. The slave receives this address and sends an acknowledgment (ACK).4.Data Write: The master sends the data to be written. The slave receives the data and sends an acknowledgment (ACK).5.Repeated Start Condition: Instead of a stop condition, the master sends a repeated start condition without releasing the bus.6.Address Phase (Read): The master sends the slave address (0xD1) with the read bit (1) set, indicating a read operation. The slave receives this address and sends an acknowledgment (ACK).7.Data Read: The slave send data from the specified register, and the master receives the data and acknowledges (ACK) byte received.8.Stop Condition (Read): The transaction concludes with a stop condition.

author: DavidAlfa
author_rank: Super Contributor
timestamp: October 17, 2023, 01:45:27 pm
content: https://www.dmi.unict.it/santoro/teaching/lsm/slides/I2C_MCU.pdfhttps://www.ti.com/lit/an/slva704/slva704.pdf?ts=1697523767470https://www.analog.com/en/technical-articles/i2c-primer-what-is-i2c-part-1.htmlhttps://www.analog.com/en/technical-articles/i2c-timing-definition-and-specification-guide-part-2.html

author: woofy
author_rank: Frequent Contributor
timestamp: October 17, 2023, 02:09:24 pm
content: Quote from: Mtech1 on October 17, 2023, 10:49:14 amMost unlikely.Have you read the I2C specification:https://www.nxp.com/docs/en/user-guide/UM10204.pdfWhat device you are trying to read/write to.Show the code you have tried so far, and which processor its for.

author: Mtech1
author_rank: Contributor
timestamp: October 17, 2023, 05:38:12 pm
content: Quote from: woofy on October 17, 2023, 02:09:24 pmI don't have a specific device or code in mind, as I was providing a general explanation of I2C transactions.I thought that understanding general I2C transactions wouldn't requires knowledge of perticular processor and slave device, you can consider divides s like the Arduino mega , P89v51rd2 and DS1307.

author: woofy
author_rank: Frequent Contributor
timestamp: October 17, 2023, 06:43:20 pm
content: I really recommend you read all the links provided above, its all there.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: October 17, 2023, 07:59:41 pm
content: Quote from: Mtech1 on October 17, 2023, 05:38:12 pmThe bit level i2c detail is common, but the message framing certainly varies with device, so you do need to pick a slave device to study.A simple GPIO device like PCF8574, has simpler transactions than an EEPROM memory or RTC for example.