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