i2c-protocol.rst 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ================
  2. The I2C Protocol
  3. ================
  4. This document describes the I2C protocol. Or will, when it is finished :-)
  5. Key to symbols
  6. ==============
  7. =============== =============================================================
  8. S Start condition
  9. P Stop condition
  10. Rd/Wr (1 bit) Read/Write bit. Rd equals 1, Wr equals 0.
  11. A, NA (1 bit) Acknowledge (ACK) and Not Acknowledge (NACK) bit
  12. Addr (7 bits) I2C 7 bit address. Note that this can be expanded as usual to
  13. get a 10 bit I2C address.
  14. Comm (8 bits) Command byte, a data byte which often selects a register on
  15. the device.
  16. Data (8 bits) A plain data byte. Sometimes, I write DataLow, DataHigh
  17. for 16 bit data.
  18. Count (8 bits) A data byte containing the length of a block operation.
  19. [..] Data sent by I2C device, as opposed to data sent by the
  20. host adapter.
  21. =============== =============================================================
  22. Simple send transaction
  23. =======================
  24. Implemented by i2c_master_send()::
  25. S Addr Wr [A] Data [A] Data [A] ... [A] Data [A] P
  26. Simple receive transaction
  27. ==========================
  28. Implemented by i2c_master_recv()::
  29. S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
  30. Combined transactions
  31. =====================
  32. Implemented by i2c_transfer().
  33. They are just like the above transactions, but instead of a stop
  34. condition P a start condition S is sent and the transaction continues.
  35. An example of a byte read, followed by a byte write::
  36. S Addr Rd [A] [Data] NA S Addr Wr [A] Data [A] P
  37. Modified transactions
  38. =====================
  39. The following modifications to the I2C protocol can also be generated by
  40. setting these flags for I2C messages. With the exception of I2C_M_NOSTART, they
  41. are usually only needed to work around device issues:
  42. I2C_M_IGNORE_NAK:
  43. Normally message is interrupted immediately if there is [NA] from the
  44. client. Setting this flag treats any [NA] as [A], and all of
  45. message is sent.
  46. These messages may still fail to SCL lo->hi timeout.
  47. I2C_M_NO_RD_ACK:
  48. In a read message, master A/NA bit is skipped.
  49. I2C_M_NOSTART:
  50. In a combined transaction, no 'S Addr Wr/Rd [A]' is generated at some
  51. point. For example, setting I2C_M_NOSTART on the second partial message
  52. generates something like::
  53. S Addr Rd [A] [Data] NA Data [A] P
  54. If you set the I2C_M_NOSTART variable for the first partial message,
  55. we do not generate Addr, but we do generate the start condition S.
  56. This will probably confuse all other clients on your bus, so don't
  57. try this.
  58. This is often used to gather transmits from multiple data buffers in
  59. system memory into something that appears as a single transfer to the
  60. I2C device but may also be used between direction changes by some
  61. rare devices.
  62. I2C_M_REV_DIR_ADDR:
  63. This toggles the Rd/Wr flag. That is, if you want to do a write, but
  64. need to emit an Rd instead of a Wr, or vice versa, you set this
  65. flag. For example::
  66. S Addr Rd [A] Data [A] Data [A] ... [A] Data [A] P
  67. I2C_M_STOP:
  68. Force a stop condition (P) after the message. Some I2C related protocols
  69. like SCCB require that. Normally, you really don't want to get interrupted
  70. between the messages of one transfer.