IIC總線接口基礎知識

原文鏈接:IIC總線接口基礎知識

目錄

1、I2C Interface

1.1 、 I2C Enable / Disable

1.2、 Start & Stop Condition

1.3 、Data validity

1.4、 Byte Format

1.5 、Acknowledge

2、 First Byte

2.1、 Slave Address

2.2、 R/W(頭上有個橫槓代表低電平有效)

3、 Transferring Data

3.1、 Write Operation

3.2、Read Operation

3.3、 Read/Write Operation

4、 I2C write and read operations in normal mode


1、I2C Interface

1.1 、 I2C Enable / Disable

If the SDA or SCL signal goes to low, I2C control block is enabled automatically. And if the SDA and SCL signal maintain high during about 2 us, I2C control block is disabled automatically also.

如果SDA或SCL信號變爲低電平,則自動啓用I2C控制模塊。 如果SDA和SCL信號在大約2 us期間保持高電平,I2C控制模塊也自動禁用。

 

1.2、 Start & Stop Condition

  • Start Condition (S) 
  • Stop Condition (P)  
  • Repeated Start (Sr)

當SCL保持再高電平,SDA由高電平變爲低電平爲開始信號。

當SCL保持在高電平,SDA由低電平變爲高電平爲停止信號。

 

1.3 、Data validity

The SDA should be stable when the SCL is high and the SDA can be changed when the SCL is low.

當SCL爲高電平時,SDA應保持穩定,當SCL爲低電平時,SDA可以更改。

1.4、 Byte Format

The byte structure is composed with 8Bit data and an acknowledge signal.

字節結構由8Bit數據和確認信號組成。

 

1.5 、Acknowledge

It is a check bit whether the receiver gets the data from the transmitter without error or not. The receiver will write ‘0’ when it received the data successfully and ‘1’ if not.

檢測接收器是否有無錯誤地從發送器獲取數據。 接收器在成功接收數據時寫入“0”,否則寫入“1”。

 

2、 First Byte

2.1、 Slave Address

It is the first byte from the start condition. It is used to access the slave device.

它是起始條件後的第一個字節。 它用於訪問從設備。列舉一個ADSTS20觸摸芯片的例子。

                                                                  TS20 Chip Address : 7bit

ADD Address
GND 0xD4
VSS 0xF4

ADD是從地址選擇腳,ADD接地(GND),從地址就是0xD4,ADD接電源(VSS),從地址就是0xF4。

 

2.2、 R/W(頭上有個橫槓代表低電平有效)

The direction of data is decided by the bit and it follows the address data.

這個位決定數據的方向(發送或者接收),它緊跟着從地址。

R/W = 1 ;代表要從從地址讀數據,反之則是要寫數據。

 

3、 Transferring Data

3.1、 Write Operation

The byte sequence is as follows:

  1. The first byte gives the device address plus the direction bit (R/W = 0).
  2. The second byte contains the internal address of the first register to be accessed.
  3. The next byte is written in the internal register. Following bytes are written in successive internal registers.
  4. The transfer lasts until stop conditions are encountered.
  5. The TS20 acknowledges every byte transfer.

字節序列如下:(這裏看不懂沒關係,後面Write操作的例程

  1. 第一個字節給出器件地址加方向位(R / W = 0)。
  2. 第二個字節,簡單說就是主機要訪問從設備的寄存器的首地址。比如是0x05,就是從第五個寄存器開始訪問。
  3. 後面傳送的數據都會寫入從設備內部寄存器中,從第二個步驟傳送的地址開始寫入。
  4. 轉移持續到遇到停止條件。
  5. TS20確認每個字節傳輸。

3.2、Read Operation

The address of the first register to read is programmed in a write operation without data, and terminated by the
stop condition. Then, another start is followed by the device address and R/W= 1. All following bytes are now
data to be read at successive positions starting from the initial address.

簡而言之就是說,想要讀取一個數據,就要先用寫命令(R/W = 0)將從設備的地址和第一個要讀取的寄存器地址給傳送出去,後面不傳送數據直接發送停止信號。然後就可以用讀命令從上一步驟發送的寄存器地址開始讀取數據了。

3.3、 Read/Write Operation

4、 I2C write and read operations in normal mode

我覺得下面這個例程看懂了,再去理解上面的就很容易了。

歡迎交流......

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章