blob: b2092f8f815dd2135e6719033bbe6d457850325d [file] [log] [blame]
Luca Ceresolif6fcefa2020-01-29 16:19:51 +01001================
2The I2C Protocol
3================
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -03004
Luca Ceresoli2f07c052020-01-29 16:19:29 +01005This document describes the I2C protocol. Or will, when it is finished :-)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
7Key to symbols
8==============
9
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030010=============== =============================================================
Luca Ceresoli02622c82020-01-29 16:19:34 +010011S Start condition
12P Stop condition
13Rd/Wr (1 bit) Read/Write bit. Rd equals 1, Wr equals 0.
Luca Ceresolidb0d7422020-01-29 16:19:35 +010014A, NA (1 bit) Acknowledge (ACK) and Not Acknowledge (NACK) bit
Luca Ceresoli02622c82020-01-29 16:19:34 +010015Addr (7 bits) I2C 7 bit address. Note that this can be expanded as usual to
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 get a 10 bit I2C address.
Luca Ceresoli02622c82020-01-29 16:19:34 +010017Comm (8 bits) Command byte, a data byte which often selects a register on
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 the device.
Luca Ceresoli02622c82020-01-29 16:19:34 +010019Data (8 bits) A plain data byte. Sometimes, I write DataLow, DataHigh
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 for 16 bit data.
Luca Ceresoli02622c82020-01-29 16:19:34 +010021Count (8 bits) A data byte containing the length of a block operation.
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Luca Ceresoli02622c82020-01-29 16:19:34 +010023[..] Data sent by I2C device, as opposed to data sent by the
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030024 host adapter.
25=============== =============================================================
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27
28Simple send transaction
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030029=======================
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Luca Ceresolica5dbb02020-01-29 16:19:52 +010031Implemented by i2c_master_send()::
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33 S Addr Wr [A] Data [A] Data [A] ... [A] Data [A] P
34
35
36Simple receive transaction
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030037==========================
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Luca Ceresolica5dbb02020-01-29 16:19:52 +010039Implemented by i2c_master_recv()::
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41 S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
42
43
44Combined transactions
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030045=====================
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Luca Ceresolica5dbb02020-01-29 16:19:52 +010047Implemented by i2c_transfer().
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Luca Ceresolif9547312020-01-29 16:19:33 +010049They are just like the above transactions, but instead of a stop
50condition P a start condition S is sent and the transaction continues.
51An example of a byte read, followed by a byte write::
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53 S Addr Rd [A] [Data] NA S Addr Wr [A] Data [A] P
54
55
56Modified transactions
57=====================
58
Wolfram Sang9f02fba2014-04-06 13:37:38 +020059The following modifications to the I2C protocol can also be generated by
Luca Ceresoli2f07c052020-01-29 16:19:29 +010060setting these flags for I2C messages. With the exception of I2C_M_NOSTART, they
Wolfram Sang9f02fba2014-04-06 13:37:38 +020061are usually only needed to work around device issues:
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Wolfram Sang9f02fba2014-04-06 13:37:38 +020063I2C_M_IGNORE_NAK:
64 Normally message is interrupted immediately if there is [NA] from the
65 client. Setting this flag treats any [NA] as [A], and all of
66 message is sent.
67 These messages may still fail to SCL lo->hi timeout.
68
69I2C_M_NO_RD_ACK:
70 In a read message, master A/NA bit is skipped.
71
72I2C_M_NOSTART:
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 In a combined transaction, no 'S Addr Wr/Rd [A]' is generated at some
74 point. For example, setting I2C_M_NOSTART on the second partial message
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030075 generates something like::
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 S Addr Rd [A] [Data] NA Data [A] P
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 If you set the I2C_M_NOSTART variable for the first partial message,
Luca Ceresolif9547312020-01-29 16:19:33 +010080 we do not generate Addr, but we do generate the start condition S.
81 This will probably confuse all other clients on your bus, so don't
82 try this.
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Mark Brown14674e72012-05-30 10:55:34 +020084 This is often used to gather transmits from multiple data buffers in
85 system memory into something that appears as a single transfer to the
86 I2C device but may also be used between direction changes by some
87 rare devices.
88
Wolfram Sang9f02fba2014-04-06 13:37:38 +020089I2C_M_REV_DIR_ADDR:
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 This toggles the Rd/Wr flag. That is, if you want to do a write, but
91 need to emit an Rd instead of a Wr, or vice versa, you set this
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030092 flag. For example::
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 S Addr Rd [A] Data [A] Data [A] ... [A] Data [A] P
95
Wolfram Sang9f02fba2014-04-06 13:37:38 +020096I2C_M_STOP:
97 Force a stop condition (P) after the message. Some I2C related protocols
98 like SCCB require that. Normally, you really don't want to get interrupted
99 between the messages of one transfer.