Author Topic: I2C Slave Read Operation  (Read 1317 times)

0 Members and 1 Guest are viewing this topic.

Offline Mtech1Topic starter

  • Contributor
  • Posts: 28
  • Country: in
I2C Slave Read Operation
« on: October 16, 2023, 11:48:47 am »
Hi,

I'm not sure about how a slave read operation is done in I2C communication, so I'll explain the steps, what I understand
so 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 slave
5. 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.

 

Offline woofy

  • Frequent Contributor
  • **
  • Posts: 338
  • Country: gb
    • Woofys Place
Re: I2C Slave Read Operation
« Reply #1 on: October 16, 2023, 12:02:01 pm »
Hi,

I'm not sure about how a slave read operation is done in I2C communication, so I'll explain the steps, what I understand
so far from documents  but please correct me if I'm wrong.

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 slave
5. 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.

No, 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.


Offline Mtech1Topic starter

  • Contributor
  • Posts: 28
  • Country: in
Re: I2C Slave Read Operation
« Reply #2 on: October 17, 2023, 10:49:14 am »
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.

« Last Edit: October 17, 2023, 10:52:22 am by Mtech1 »
 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5956
  • Country: es
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline woofy

  • Frequent Contributor
  • **
  • Posts: 338
  • Country: gb
    • Woofys Place
Re: I2C Slave Read Operation
« Reply #4 on: October 17, 2023, 02:09:24 pm »
7. Data Read: The slave send  data from the specified register, and the master receives the data and acknowledges (ACK) byte received.
Most unlikely.

Have you read the I2C specification:
https://www.nxp.com/docs/en/user-guide/UM10204.pdf

What device you are trying to read/write to.
Show the code you have tried so far, and which processor its for.

Offline Mtech1Topic starter

  • Contributor
  • Posts: 28
  • Country: in
Re: I2C Slave Read Operation
« Reply #5 on: October 17, 2023, 05:38:12 pm »
What device you are trying to read/write to.
Show the code you have tried so far, and which processor its for.


I 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.
 

Offline woofy

  • Frequent Contributor
  • **
  • Posts: 338
  • Country: gb
    • Woofys Place
Re: I2C Slave Read Operation
« Reply #6 on: October 17, 2023, 06:43:20 pm »
I really recommend you read all the links provided above, its all there.

Online PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 1570
  • Country: au
Re: I2C Slave Read Operation
« Reply #7 on: October 17, 2023, 07:59:41 pm »
I 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.

The 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf