I2C介面學習筆記

介面名稱:IIC或I2C

英文全稱:Inter-integrated Circuit

中文:積體電路匯流排

標準維護和制定:NA

發明者:PHILIPS(1982年)

(現為N

XP

Semiconductors

當前規範

I2C-bus specification and user manual

最新版本:V6(1992年釋放V1。)

生效時間:2014。04。04

下一版本:NA

說明:I2C為全雙工雙向序列匯流排,一根是雙向的資料線SDA,另一根是時鐘線SCL。其資料傳輸速率有以下5種:

u標準模式SM(Standard mode):100kbps;(雙向)

u快速模式FM(Fast mode):400Kbps;(雙向)

u快速+FM+(Fast Mode Plus):1Mbps;(雙向)

u高速模式HS(High speed mode):3。4Mbps;(雙向)

u超快速模式UFM(Ultra Fast-mode):5Mbps(單向)

注:行業內許多匯流排介面都採用IIC介面作為基礎然後進行修改和適配。如

IPMI:Intelligent Platform Management Interface(www。intel。com/design/servers/ipmi/ipmi。htm)

ATCA:Advanced Telecom Computing Architecture

(www。picmg。org/v2internal/resourcepage2。cfm?id=2)

普通I

2C

(不含U

FM

)匯流排配置示意圖

U

FM I2C

匯流排配置示意圖

I2C介面學習筆記

一、介面結構

I2C匯流排採用二線制傳輸,一根是資料線SDA(Serial Data Line),另一根是時鐘線SCL(Serial Clock line),所有I2C器件都連線在SDA和SCL上,每一個器件具有一個唯一的地址。其架構如下圖所示。可以連線幾個器件取決於

匯流排電容

的限制。

I

2C

匯流排中有一個傳送器(

Transmitter

和一個接收器(

Receiver

。在邏輯上,又根據角色分為M

aster

和S

lave

兩種。

I2C匯流排支援多主(multi-mastering)和主從(master-slave)兩種工作方式。

主機是指啟動資料的傳送(發起始訊號)、發出時鐘訊號、發出終止訊號的器件。通常,主機由微控制器或其它微處理器擔任。

n多主方式下,I2C總線上可以有多個主機。I2C匯流排需透過硬體和軟體仲裁來確定主機對匯流排的控制權。

n主從工作方式時,系統中只有一個主機,總線上的其它器件均為從機(具有I2C匯流排介面),只有主機能對從機進行讀寫訪問,因此,不存在匯流排的競爭等問題。在主從方式下,I2C匯流排的時序可以模擬,I2C匯流排的使用不受主機是否具有I2C匯流排介面的制。

I2C介面學習筆記

I2C介面學習筆記

二、工作原理

2。1非超高速模式I2C匯流排工作原理

2。1。1資料位傳輸BITTRANSFER

I2C總線上主機與從機之間一次傳送的資料稱為一幀。由

啟動訊號、若干個資料位元組、應答位和停止訊號

組成。資料傳送的基本單元為8位資料,每個位元組後面必須跟隨一個ACK位。資料傳輸是MSB(Most Significant Bit)優先。

時鐘線SCL的一個時鐘週期只能傳輸一位資料。在SCL時鐘線為高電平期間內,資料線SDA上的資料必須穩定。當SCL時鐘線變為低電平時,資料線SDA的狀態才能改變。

I2C介面學習筆記

2.

1

.

2

啟動和停止

START

&

STOP conditions

起始(START)狀態:I2C匯流排傳輸過程中,當時鍾線SCL為高電平,資料線SDA出現高電平到低電平跳變時,標誌I2C匯流排傳輸資料開始。

停止(STOP)狀態:I2C匯流排傳輸過程中,當時鍾線SCL為高電平,資料線SDA出現低電平到高電平跳變時,標誌著I2C匯流排傳輸資料結束。

2.

1

.

3

資料的傳送

TRANSFERRING DATA

每次傳輸的位元組數不受限制。每個位元組後必須跟一個應答(acknowledge)位。資料傳輸時,首先傳送最高位,如圖10。5所示,如果從機暫時不能接收下一個位元組資料,如從機響應內部中斷,那麼,可以使時鐘線SCL保持為低電平,迫使主機處於等待狀態;當從機準備就緒後,再釋放時鐘線SCL,使資料傳輸繼續進行。

I2C介面學習筆記

2.

1

.

4

應答

Acknowledge

I2C協議規定,在每個位元組傳送完畢後,必須有一個應答位。應答位的時鐘脈衝由主機產生。在應答時鐘有效期間,傳送裝置把資料線SDA置為高電平;接收裝置必須把資料線SDA置為低電平,並且在此期間保持低電平狀態,以便產生有效的應答訊號。

I2C介面學習筆記

2.

1

.

5

資料傳輸格式

在起始狀態S之後,先發送一個7位從機地址(或1位地址),接著第8位是資料方向位,=表示傳送(寫),=1表示請求資料(讀)。

一次資料傳輸總是由主機產生停止狀態P而結束。但是,如果主機還希望在總線上傳輸資料,那麼,它可以產生另一個起始狀態和定址另一個從機,不需要先產生一個停止狀態。在這種傳輸方式中,就可能有讀寫方式的組合。

I2C介面學習筆記

在I2C匯流排啟動或應答訊號後的第1~8個時鐘脈衝,對應一個位元組的8位資料傳送。高電平期間,資料序列傳送;低電平期間為資料準備,允許總線上資料電平變化。一旦I2C匯流排啟動,傳送的位元組數沒有限制,只要求每傳送一個位元組後,對方迴應一個應答位。傳送時,最先發送的是資料的最高位。每次傳送開始有起始訊號,結束時有停止訊號。傳送完一個位元組,可以透過對時鐘線的控制使傳送暫停

I2C介面學習筆記

一個SLAVE器件有

7

位和1

位地址(可支援1

024

個器件)

兩種。使用1位地址格式時,第一個位元組的前7位確定地址,第8位確定R(讀,高電平)還是/W(寫,低電平)。

2.

2

超快速模式U

FM I2C

匯流排工作原理

超高速I2C匯流排的速率可達5Mbps,由於其是單向傳輸(主至從)其常見用於LED驅動器件,此時MCU作為傳送器,LED驅動器件作為接收器。其傳輸還是基於普通I2C,傳輸包括START啟動位, slave address被動器件地址,command命令位, ninth clock第九時鐘和STOP位等。它的兩根線為區別普通I2C,分別被稱之為USDA和USCL。其配置可參考下圖。

I2C介面學習筆記

2.

2

.

1 UFM

模式I

2C

的信令和邏輯電平

邏輯電平同普通I2C,依賴於VDD電壓,一般為低電平為0。3VDD,高電平為0。7VDD。

I2C介面學習筆記

2.

2

.

2 UFM I2C

位傳輸

位傳輸示意圖見下圖所示

I2C介面學習筆記

2.

2

.

3

啟動和停止

I2C介面學習筆記

2.

2

.

4

位元組格式

I2C介面學習筆記

2.

2

.

5

資料傳輸

I2C介面學習筆記

I2C介面學習筆記

2.

2

.

6

啟動位元組

I2C介面學習筆記

2.

2

.

7

Device ID

在UFM時,不支援Device ID。

2.

2

.

8

軟體復位

Following a General Call, (0000 0000), sending 0000 0110 (06h) as the second byte

causes a software reset。 This feature is optional and not all devices respond to this

command。 On receiving this 2-byte sequence, all devices designed to respond to the

general call address reset and take in the programmable part of their address。

三、應用設計

普通SDA和SCL線介面一般設計為

開集或開漏;但對於U

FM

模式(最高達5

M

bps

的S

DA

和S

CL

則是推輓輸出(Push

-Pull

out

put)

,如下圖所示,當匯流排處於空閒狀態時,

USCL

和U

SDA

腳上部三極體導通而處於高電平。

不管是普通SDA和SCL還是USDA和USCL,其邏輯電平不依賴於訊號電平的大小,而是與供電電壓成正比,即一般為輸入低電平VIL為0。3VDD,輸入高電平VIH為0。7VDD。

注意:

U

FM

匯流排(單向)不能相容普通的、前面4種模式的I

2C

匯流排(它們需要電流源或上拉電阻且為雙向)

I2C介面學習筆記

I2C介面學習筆記

3.

1

上拉電阻的選擇

一個標準模式的I2C匯流排,其連線結構如下圖所示。在這種連線結構中,我們來討論如何確定上拉電阻Rp和串聯電阻Rs(防止高壓脈衝衝擊)的取值範圍,進而確定一個阻值的選擇規則。

I2C介面學習筆記

根據I2C匯流排的原理,Rp取值的範圍取決於以下三個要素:

²供電電壓

²匯流排電容

²總線上所聯結器件的個數(輸入電流+漏電電流)

對於I

2C

輸出,因為匯流排要求

VOLmax = 0.4 V

時,標準和快速模式下其S

INK

灌電流最小值為3

mA

、快速+模式下為2

0mA,

因此,

供電電壓限制了Rp的最小值。具體關係見下圖3.

1

所示。

I2C介面學習筆記

圖3.

1 R

p最小值與供電電壓V

DD

的關係

例如

:假設供電電壓為VDD=5V±10%,VOLmax=0。4 V@3 mA,則Rpmin =

(5。5-0。4)/0。003=1。7 KΩ

匯流排電容是所聯結器件的引腳、線纜或線路以及聯結器等共同作用的等效電容,其總的等效電容量會影響時鐘的上升時間tr,因此,電容Cb與上升時間tr成正比,即電容越大,上升時間tr越大,例如,在標準模式(即速率為100Kbps)時,總等效電容Cb不能大於400pF(快速模式時不能大於100pF,其餘值可根據速率而定)。可以說,此電容Cb值確定了Rp(上拉電阻)的最大值。計算公式見如下,具體關係見下圖3。2所示。

式中,t

r

為上升時間,C

b

為匯流排電容

圖3.

2 R

P

最大值與匯流排電容的關係

I2C介面學習筆記

3.

2 Rs

電阻的選擇

低電平的噪聲裕量要求為0。1VDD,因此,此電平的要求限制了Rs的最大值,同時此電阻值也會影響下降時間tf。

供電V

DD

、R

p

和R

s

三者之間的關係見下圖3.

3

所示

圖3。3供電VDD、Rp和Rs三者之間的關係

I2C介面學習筆記

3。3

輸入漏電流

Input leakage

輸入高電平最大漏電流為10uA,且高電平時的噪聲裕量為0。2VDD,這兩個要素就限制了Rp的最大值。其關係圖見下圖3。4所示。

I2C介面學習筆記

圖3。4輸入高電平漏電流與VDD和Rp電阻取值的關係函式

3。4

標準、快速、快速+及高速模式I

2C

匯流排的特性引數

表3。1。 SDA和SCL I/O的特性引數表

I2C介面學習筆記

[1] Some legacy Standard-mode devices had fixed input levels of VIL = 1。5 V and VIH = 3。0 V。 Refer to component data sheets。

[2] Maximum VIH = VDD(max) + 0。5 V or 5。5 V, whichever is lower。 See component data sheets。

[3] The same resistor value to drive 3 mA at 3。0 V VDD provides the same RC time constant when using

[4] In order to drive full bus load at 400 kHz, 6 mA IOL is required at 0。6 V VOL。 Parts not meeting this specification can still function, but not at 400 kHz and 400 pF。

[5] The maximum tf for the SDA and SCL bus lines quoted in表3。2(300 ns) is longer than the specified maximum tof for the output stages (250 ns)。 This allows series protection resistors (Rs) to be connected between the SDA/SCL pins and the SDA/SCL bus lines as shown inFigure 45without exceeding the maximum specified tf。

[6] Necessary to be backwards compatible with Fast-mode。

[7] In Fast-mode Plus, fall time is specified the same for both output stage and bus timing。 If series resistors are used, designers should allow for this when considering bus timing。

[8] Input filters on the SDA and SCL inputs suppress noise spikes of less than 50 ns。

[9] If VDD is switched off, I/O pins of Fast-mode and Fast-mode Plus devices must not obstruct the SDA and SCL lines。

[10] Special purpose devices such as multiplexers and switches may exceed this capacitance because they connect multiple paths together

3

.

2.

標準、快速及快速+等模式下I

2C

匯流排器件

SDA

SCL

的特性引數

[1

I2C介面學習筆記

[1] All values referred to VIH(min) (0。3VDD) and VIL(max) (0。7VDD) levels (seeTable 9)。

[2] tHD;DAT is the data hold time that is measured from the falling edge of SCL, applies to data in transmission and the acknowledge。

[3] A device must internally provide a hold time of at least 300 ns for the SDA signal (with respect to the VIH(min) of the SCL signal) to bridge the undefined region of the falling edge of SCL。

[4] The maximum tHD;DAT could be 3。45μs and 0。9μs for Standard-mode and Fast-mode, but must be less than the maximum of tVD;DAT or tVD;ACK by a transition time。 This maximum must only be met if the device does not stretch the LOW period (tLOW) of the SCL signal。 If the clock stretches the SCL, the data must be valid by the set-up time before it releases the clock。

[5] A Fast-mode I2C-bus device can be used in a Standard-mode I2C-bus system, but the requirement tSU;DAT 250 ns must then be met。 This will automatically be the case if the device does not stretch the LOW period of the SCL signal。 If such a device does stretch the LOW period of the SCL signal, it must output the next data bit to the SDA line tr(max) + tSU;DAT = 1000 + 250 = 1250 ns (according to the Standard-mode I2C-bus specification) before the SCL line is released。 Also the acknowledge timing must meet this set-up time。

[6] If mixed with Hs-mode devices, faster fall times according to表3。2are allowed。

[7] The maximum tffor the SDA and SCL bus lines is specified at 300 ns。 The maximum fall time for the SDA output stage tfis specified at 250 ns。 This allows series protection resistors to be connected in between the SDA and the SCL pins and the SDA/SCL bus lines without exceeding the maximum specified tf。

[8] In Fast-mode Plus, fall time is specified the same for both output stage and bus timing。 If series resistors are used, designers should allow for this when considering bus timing。

[9] Necessary to be backwards compatible to Fast-mode。

[10] The maximum bus capacitance allowable may vary from this value depending on the actual operating voltage and frequency of the application。具體可參考I2C匯流排標準文件。

[11] tVD;DAT = time for data signal from SCL LOW to SDA output (HIGH or LOW, depending on which one is worse)。

[12] tVD;ACK = time for Acknowledgement signal from SCL LOW to SDA output (HIGH or LOW, depending on which one is worse)。

I2C介面學習筆記

表3。3高速模式I2C匯流排器件SDAH, SCLH, SDA和SCL I/O特性引數

I2C介面學習筆記

[1] Devices that use non-standard supply voltages which do not conform to the intended I2C-bus system levels must relate their input levels to the VDD voltage to which the pull-up resistors Rp are connected。

[2] Devices that offer the level shift function must tolerate a maximum input voltage of 5。5 V at SDA and SCL。

[3] For capacitive bus loads between 100 pF and 400 pF, the rise and fall time values must be linearly interpolated。

[4] If their supply voltage has been switched off, SDAH and SCLH I/O stages of Hs-mode slave devices must have floating outputs。 Due to the current-source output circuit, which normally has a clipping diode to VDD, this requirement is not mandatory for the SCLH or the SDAH I/O stage of Hs-mode master devices。 This means that the supply voltage of Hs-mode master devices cannot be switched off without affecting the SDAH and SCLH lines。

[5] Special purpose devices such as multiplexers and switches may exceed this capacitance because they connect multiple paths together

I2C介面學習筆記

表3。4高速模式Hs I2C-匯流排器件SDAH, SCLH, SDA和SCL特性引數[1]

[1] All values referred to VIH(min) and VIL(max) levels (see表3。3)。

[2] For bus line loads Cb between 100 pF and 400 pF the timing parameters must be linearly interpolated。

[3] A device must internally provide a data hold time to bridge the undefined part between VIH and VIL of the falling edge of the SCLH signal。 An input circuit with a threshold as low as possible for the falling edge of the SCLH signal minimizes this hold time。

I2C介面學習筆記

3。5

UFM

模式匯流排特性引數

表3。5 USDA和USCL I/O特性引數表。

[1] Refer to component data sheets for actual switching points。

[2] Maximum VIH = VDD(max) + 0。5 V or 5。5 V, whichever is lower。 See component data sheets。

[3] Special purpose devices such as multiplexers and switches may exceed this capacitance because they connect multiple paths together。

[4] Input filters on the USDA and USCL slave inputs suppress noise spikes of less than 10 ns。

I2C介面學習筆記

表3。6。 UFm模式I2C匯流排頻率和時間規格表

I2C介面學習筆記

[1] tVD;DAT = minimum time for USDA data out to be valid following USCL LOW。

[2] Typical rise time or fall time for UFm signals is 25 ns measured from the 30 % level to the 70 % level (rise time) or from the 70 % level to the 30 % level (fall time)。

I2C介面學習筆記

3

.6

電平轉換電路的設計

因為半導體技術的發展,產生了各種電壓的信令及介面,如TTL、CMOS、LVTTL、LVCMOS、ECL、PECL、LVPECL、CML、VML等,電壓有5V、3。3V、1。8V、1。5V、1。2V、0。6V等等。下面簡單介紹一下,電平轉換電路,以便I2C電路在不同的電平之間也能起工作。

下圖圖3。5中,VDD1=3。3V代表低壓端,也可以是2。5V、1。8V等其它電壓,VDD2=5V代表高壓端,也可以是其它電壓,如12V、9V等,原則上就是VDD2>=VDD1。兩個N溝通增強型MOS場效電晶體TR1、TR2充當SCL和SDA線電平轉換作用,MOS管G極接低壓VDD1端,MOS管S端(源極)接低壓端SDA1或SCL1,MOS管D端(漏極)接高壓端SDA2或SCL2。其工作原理解釋如下:

u當I2C匯流排空閒時,TR1/TR2 G和S電平均為3。3V,則GS低於導通電壓不能導通而MOS管截止,匯流排高壓端與低壓端均保持高電平而相互不受影響;

u當低壓端匯流排拉低時,TR1/TR2 G端保持3。3V,S端被拉低電,所以GS高於導通電壓而MOS管DS導通,將把SDA2/SCL2的電平拉到低電平狀態;

u當高壓端匯流排拉低時,TR1/TR2內建的、並聯在D、S兩極的反向二極體會導通,直到GS超過導通門限而導通,從而把SDA1/SCL1也拉到低電平。

I2C介面學習筆記

圖3。5電平轉換電路原理圖

四、測試驗證

I2C匯流排設計上比較簡單,測試也比較簡單,用邏輯分析儀和數字示波器就能很好的進行分析,本節就不再介紹

————————————————————————-The End————————————————————————

頂部