i2c-protocol 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. This document describes the i2c protocol. Or will, when it is finished :-)
  2. Key to symbols
  3. ==============
  4. S (1 bit) : Start bit
  5. P (1 bit) : Stop bit
  6. Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
  7. A, NA (1 bit) : Accept and reverse accept bit.
  8. Addr (7 bits): I2C 7 bit address. Note that this can be expanded as usual to
  9. get a 10 bit I2C address.
  10. Comm (8 bits): Command byte, a data byte which often selects a register on
  11. the device.
  12. Data (8 bits): A plain data byte. Sometimes, I write DataLow, DataHigh
  13. for 16 bit data.
  14. Count (8 bits): A data byte containing the length of a block operation.
  15. [..]: Data sent by I2C device, as opposed to data sent by the host adapter.
  16. Simple send transaction
  17. ======================
  18. This corresponds to i2c_master_send.
  19. S Addr Wr [A] Data [A] Data [A] ... [A] Data [A] P
  20. Simple receive transaction
  21. ===========================
  22. This corresponds to i2c_master_recv
  23. S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
  24. Combined transactions
  25. ====================
  26. This corresponds to i2c_transfer
  27. They are just like the above transactions, but instead of a stop bit P
  28. a start bit S is sent and the transaction continues. An example of
  29. a byte read, followed by a byte write:
  30. S Addr Rd [A] [Data] NA S Addr Wr [A] Data [A] P
  31. Modified transactions
  32. =====================
  33. We have found some I2C devices that needs the following modifications:
  34. Flag I2C_M_NOSTART:
  35. In a combined transaction, no 'S Addr Wr/Rd [A]' is generated at some
  36. point. For example, setting I2C_M_NOSTART on the second partial message
  37. generates something like:
  38. S Addr Rd [A] [Data] NA Data [A] P
  39. If you set the I2C_M_NOSTART variable for the first partial message,
  40. we do not generate Addr, but we do generate the startbit S. This will
  41. probably confuse all other clients on your bus, so don't try this.
  42. Flags I2C_M_REV_DIR_ADDR
  43. This toggles the Rd/Wr flag. That is, if you want to do a write, but
  44. need to emit an Rd instead of a Wr, or vice versa, you set this
  45. flag. For example:
  46. S Addr Rd [A] Data [A] Data [A] ... [A] Data [A] P
  47. Flags I2C_M_IGNORE_NAK
  48. Normally message is interrupted immediately if there is [NA] from the
  49. client. Setting this flag treats any [NA] as [A], and all of
  50. message is sent.
  51. These messages may still fail to SCL lo->hi timeout.
  52. Flags I2C_M_NO_RD_ACK
  53. In a read message, master A/NA bit is skipped.