user123456
user123456

Reputation: 21

I2C read - repeated start needed?

I have a doubt regarding read operation in I2C, bit banging. The protocol which I am following for read as below: Start-slave address with write-ack-register loc-ack-stop. ...... Start-slave address with read-ack-read data-stop. I am reading data as FFh which is wrong. My doubt is, before sending the another start, do in need to send stop or can continue the another start for reading data without stop, which actually is a repeated start. Does sending a stop bit or not makes any difference. Also can someone tell what can be the possible reason if data read is FFh. But I can guarantee that write operation is successful, after seeing the scope shot. Please guide me.

Thanks

Upvotes: 2

Views: 13859

Answers (2)

MILAD MO
MILAD MO

Reputation: 11

I just had this issue and found the reason: if you receive FFh in reading all the time, you are missing the repeated start.

Upvotes: 1

Pandrei
Pandrei

Reputation: 4961

The i2c protocol works like this

WRITE:
  1. send START
  2. write slave address with last bit as WRITE ACCESS(0)
  3. write sub-address: this is usually the address of the register you what to write to; if not applicable skip to 4.
  4. write data
  5. send STOP

Each byte you write to the slave device should be answered with an ACK if the operation was successful.

READ:
  1. send START
  2. write slave address with last bit as WRITE ACCESS(0)
  3. write sub-address: this is usually the address of the register you what to read from
  4. send START (this is a second start condition - a restart)
  5. write slave address with last bit as READ ACCESS(1)
  6. read data
  7. send STOP

All write and read operations (except the last read) are answered with a ACK if successful.

So in the case of a restart you don't send a second Stop.

As far as the 0xFF read result is concerned, you need to check the datasheet of the device, but some will return this value if the data you are trying to read is not available, yet!

Hope this helps.

Upvotes: 6

Related Questions