s5pv210 I2C通信详解

1:I2C通信原理:

I2C通信接线只有两根,SDA、SCL。

SDA用来传输地址、命令、数据。SCL用来提供时钟。

在I2C通信线上可以接多个slave device(从设备)。

I2C通信特点

(1)  每次通信都是由主设备发起,每个slave device都有固定一个通信地址,开始通信以后,主设备首先会发送7bit位的slave device地址,和1bit位的rean或者write命令,

所以理论上最多可以有27个salve device。

(2)  可以一对多通信,并且通信是同步的(syce),因为时钟是同一根时钟线来提供的,对比一下UART通信:UART Tx/Rx/GND 三根线(其他为流忽略),没有同一的时钟,所以通信

双方要约定好相同的波特率、起始、结束、校验、几字节数据位这样才能接受到正确的数据。

(3)  通信速度比较慢,从设备的时钟是由主设备提供的,即通过SCL时钟线来提供,SCL是由PCLC_PSYS(133/2)时钟频率在经2次分频得到的,正常可用SCL时钟一般为31KHz。

I2C是如何通信的?

s5pv210是发送或接受数据是如何区分多个子设备?可以看下图:开始通信以后,主设备首先会发送7bit位的slave device地址,和1bit位的rean或者write命令,

(1)  如果为write命令,则主设备free SDA通信线(If the I2C-bus is free, both SDA and SCL lines should be both at High level.三星user manual),即SDA

为高位。然后从设备先ACK主设备(拉低SDA)表示收到命令(S)。然后主设备在发送8bit数据,从设备在ACK(A)。然然后结束(P)。

(2)  如果为read命令,则从设备先ACK主设备(拉低SDA),然后发送8bit数据,主设备ACK从设备(拉低SDA),从设备在发送,直到主设备停止接收。

如下图所以,白色bit位为主设备发送,灰色bit位为从设备发送。

 I2C时序:如果I2C bus 接口不工作的时候,通常处于Slave模式,意思就是接口在开始通信之前必须要处于Slave模式。

开始通信的条件是:

(1)  SDA线由高位拉到低位,此时I2C bus接口还处于slave状态,SCL一直为高位。

(2)  设置I2C bus接口为master mode,此时产生SCL时钟信号,SDA可以传输数据、命令。

(三星数据手册:If the I2C-bus interface is inactive, it is usually in Slave mode. In other words, the interface should be in Slave mode before detecting a

Start condition on the SDA line (a Start condition is initiated with a High-to-Low transition of the SDA line while the clock signal of SCL is High).

 If the interface state is changed to Master mode, SDA line initiates data transfer and generates SCL signal.

结束通信条件:

(1)  I2C bus 接口为master mode,是SCL一直产生高电平;

(2)  SDA由低突然拉高,即结束通信;

(三星数据手册A Stop condition is a Low-to-High transition of the SDA line while SCL is High. The master generates Start and Stop conditions.

The I2C-bus gets busy if a Start condition is generated. On the other hand, a Stop condition frees the I2C-bus.)

循环通信:重复以上步骤;

(The master transmits Stop condition to complete the transfer operation. If the master wants to continue the data transmission to the bus, it should generate

another Start condition as well as a slave address.)

具体可以看下面这个图:

当I2C bus interface(应该可以通过某寄存器的某个bit位来设置)为slave模式时,SCL一直是高电平,此时拉低SDA表示开始通信,SCL产生时钟信号,结束的时候,为Master模式

拉高SDA,表示通信结束。

看通信时序图:

SCL为高位的时候,SDA发送或者接收数据,SCL为低位的时候,SDA要在这段时间把电平拉低或者拉高(这个过程需要一定时间)1-8 SCL时钟周期SDA通信线发送slave device的地址

以及read或者write命令总共8bit位。在第9个时钟周期slave device要ACK(即拉低SDA),如果发送的位read命令则,ACK之后的8个时钟周期由Slave device发送8bit数据,下一个时钟

周期主设备发送ACK(表示收到),之后结束(接口为slave模式,SDA由低拉高)

原文地址:https://www.cnblogs.com/biaohc/p/6271335.html