0%

i2c-bus

  • I2C Read时,寄存器地址是可选项,是否需要需要根据寄存器手册来确认
  • I2C每个数据后都有ACK

Write x bytes to I2C slave

  • A:Acknowledge(SDA LOW)
  • A~:Not Acknowledge(SDA HIGH)
  • S:Start Condition
  • P:Stop Condition
  • ():From slave to Master
S -> SLAVE ADDR+W -> (A) -> REGISTER -> (A) -> DATA0 -> (A) -> DATA1 -> (A) -> DATAx -> (A) -> P

Set slave data pointer

S -> SLAVE ADDR+W -> (A) -> REGISTER -> (A) -> P

Read x bytes from I2C slave

S -> SLAVE ADDR+R -> (A) -> (DATA0) -> A -> (DATA1) -> A -> (DATAx) -> A~ -> P

I2C BUS Specification

Each slave device on the bus should have a unique 7-bit address. The communication starts with the Start condition, followed by the 7-bit slave address and the data direction bit. If this bit is 0 then the master will write to the slave device. Otherwise, if the data direction bit is 1, the master will read from slave device. After the slave address and the data direction is sent, the master can continue with reading or writing. The communication is ended with the Stop condition which also signals that the I2C bus is free. If the master needs to communicate with other slaves it can generate a repeated start with another slave address without generation Stop condition. All the bytes are transferred with the MSB bit shifted first.

If the master only writes to the slave device then the data transfer direction is not changed.

S -> SLAVE ADDR+W -> (A) ->

If the master only needs to read from the slave device then it simply sends the I2C address with the R/W bit set to read. After this the master device starts reading the data.

Sometimes the master needs to write some data and then read from the slave device. In such cases it must first write to the slave device, change the data transfer direction and then read the device. This means sending the I2C address with the R/W bit set to write and then sending some additional data like register address. After writing is finished the master device generates repeated start condition and sends the I2C address with the R/W bit set to read. After this the data transfer direction is changed and the master device starts reading the data.

S -> SLAVE ADDR+W -> (A)

Ref

  1. I2C Info – I2C Bus, Interface and Protocol
  2. I2C Bus Specification
  3. Using the I2C Bus
  4. 快速简单理解i2c标准协议
  5. 巩固理解I2C协议
  6. I2C 协议分析
  7. I2c 协议解析
  8. I2C
  9. How to read IDs from I2C Devices
  10. how to read from certain register address of i2c slave with wire.h library?
  11. I2C access examples