差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
i2c [2017/03/26 21:34] gongyu [I2C总线特性] |
i2c [2023/05/30 11:13] (当前版本) gongyu |
||
---|---|---|---|
行 1: | 行 1: | ||
+ | #### I2C - 集成电路之间的同步、半双工数据传输 | ||
+ | |||
+ | --- | ||
+ | |||
I2C是一种简单地连接多个芯片的总线方式,尤其是在[[FPGA]]s/[[CPLD]]s中. | I2C是一种简单地连接多个芯片的总线方式,尤其是在[[FPGA]]s/[[CPLD]]s中. | ||
{{ ::i2cslave.gif |}} | {{ ::i2cslave.gif |}} | ||
- | ===== I2C总线特性 ===== | + | ### I2C总线特性 |
* 除了“电源”和“地”之外,只用了"SDA"和"SCL"两根信号线 | * 除了“电源”和“地”之外,只用了"SDA"和"SCL"两根信号线 | ||
* 在同一个总线上最多可以支持到100个器件,每个挂在总线的器件都有一个地址用于寻址 | * 在同一个总线上最多可以支持到100个器件,每个挂在总线的器件都有一个地址用于寻址 | ||
- | * 多个“主”设备(例如,两个CPU可以简单地共用同一个I2C器件) | + | * 多个“主”设备(例如,两个[[CPU]]可以简单地共用同一个I2C器件) |
* 为业界标准,由Philips开发, 被很多其它厂商采用 | * 为业界标准,由Philips开发, 被很多其它厂商采用 | ||
* 用途非常广泛,比如电视机、PCs | * 用途非常广泛,比如电视机、PCs | ||
行 14: | 行 18: | ||
* 不支持“即插即用” | * 不支持“即插即用” | ||
- | ===== 工作原理 ===== | ||
- | An I2C bus needs at a minimum an I2C master and an I2C slave. | ||
- | The I2C master is a transaction (a master can write-to or read-from a slave). | ||
- | The I2C slave is a transaction recipient (a slave can be written-to or read-from a master). | ||
- | ===== I2C波型 ===== | + | 一个I2C总线需要至少一个I2C主和I2C从. |
- | Here's how it looks on the bus. | + | I2C“主”即可以向“从”写也可以从“从”设备中读取 |
- | This a write to an EEPROM at address 0x51, with 2 data bytes 0x50 and 0x0F. | + | |
+ | #### I2C波形 | ||
+ | {{ :i2c_timing.png |}} | ||
+ | 这个图示为向地址为0x51的EEPROM进行写2个字节的数据0x50和0x0F. | ||
{{ ::i2c_writetoeeprom.gif |initiator}} | {{ ::i2c_writetoeeprom.gif |initiator}} | ||
- | An I2C transaction begins with a "start" condition, followed by the address of the device we wish to speak to, a bit to indicate if we want to read or write, the data written or read, and finally a "stop". | + | 一个I2C过程由"起始"开始, 接着是我们要通信的设备的地址,有一位标记此操作是“读”还是“写”;要读取或写入的“数据”,最后是个“终止”位。 |
- | There are other details, like the need to have an "acknowledge" bit after each byte transmitted... see the waveform above, and the project's links. | + | |
+ | 还有其它的一些细节,比如在每个字节传输以后需要一个”应答“位,参看波形图。 | ||
在FPGA或CPLD中有两种方式创建一个I2C从功能: | 在FPGA或CPLD中有两种方式创建一个I2C从功能: | ||
行 50: | 行 53: | ||
</code> | </code> | ||
- | Then the 7-bits address that we want for our I2C slave. | + | 接着是我们需要的I2C“从”设备的7位地址 |
<code verilog> | <code verilog> | ||
行 56: | 行 59: | ||
</code> | </code> | ||
- | Then the start and stop conditions detection logic. | + | 接着是“起始”和“终止”检测逻辑,这也是本设计中最神秘的部分。 |
- | That's the "black magic" part of this design... | + | |
<code verilog> | <code verilog> | ||
行 72: | 行 74: | ||
</code> | </code> | ||
- | Now we are ready to count the I2C bits coming in | + | 现在我们可以计数进来的I2C的位数。 |
<code verilog> | <code verilog> | ||
行 98: | 行 100: | ||
</code> | </code> | ||
- | and detect if the I2C address matches our own | + | 并且检测I2C的地址是否匹配 |
<code verilog> | <code verilog> | ||
行 132: | 行 134: | ||
</code> | </code> | ||
- | and drive the SDA line when necessary. | + | 如有需要驱动=SDA信号线 |
<code verilog> | <code verilog> | ||
行 155: | 行 157: | ||
如果你能够容忍这些缺点,这应该是I2C从模式非常简洁的设计,否则你只能用外部时钟对SDA和SCL进行过取样,通过数字滤波器将毛刺给滤除掉,“起始”和“终止”的检测也变得比较容易,当然代价就是设计变得更复杂。 | 如果你能够容忍这些缺点,这应该是I2C从模式非常简洁的设计,否则你只能用外部时钟对SDA和SCL进行过取样,通过数字滤波器将毛刺给滤除掉,“起始”和“终止”的检测也变得比较容易,当然代价就是设计变得更复杂。 | ||
- | |||
- | ====== 资源链接 ====== | ||
- | * [[http://www.nxp.com/documents/user_manual/UM10204.pdf|I2C规范]]. | ||
- | * Philips多方面深度讨论I2C的[[http://www.nxp.com/documents/application_note/AN10216.pdf|应用指南]] | ||
- | * [[http://www.esacademy.com/faq/i2c/|I2C常见问题]] | ||
- | * [[http://www.totalphase.com/support/kb/10040/|关于I2C和SMBus区别的文章]](SMBus是由Intel公司开发的,基本跟I2C兼容) | ||
- | 更多信息参见[[wikipedia上关于i2c的介绍]] | + | |
+ | ### 相关设计资源参考 | ||
+ | |||
+ | * [I2C规范](http://www.nxp.com/documents/user_manual/UM10204.pdf). | ||
+ | * Philips多方面深度讨论I2C的[应用指南](http://www.nxp.com/documents/application_note/AN10216.pdf) | ||
+ | * [I2C常见问题](http://www.esacademy.com/faq/i2c/) | ||
+ | * [关于I2C和SMBus区别的文章](http://www.totalphase.com/support/kb/10040/)(SMBus是由Intel公司开发的,基本跟I2C兼容) | ||
+ | * 苏老师公众号文章 - [几种最常用的串行数据传输总线(2)-I2C](https://mp.weixin.qq.com/s/UVlecH-zBVG5Ug4Bx6TVeQ) | ||
+ | * Lattice Semi的[I2C Master](http://www.latticesemi.com/en/Products/DesignSoftwareAndIP/IntellectualProperty/ReferenceDesigns/ReferenceDesigns02/I2CBusMaster)使用说明,及IP参考代码下载 | ||
+ | * Lattice Semi的[支持Wisbone总线的I2C Master](http://www.latticesemi.com/en/Products/DesignSoftwareAndIP/IntellectualProperty/ReferenceDesigns/ReferenceDesigns02/I2CMasterWISHBONECompatible)使用说明,及IP参考代码下载 | ||
+ | * Lattice Semi的[I2C总线控制器](http://www.latticesemi.com/en/Products/DesignSoftwareAndIP/IntellectualProperty/ReferenceDesigns/ReferenceDesigns02/I2CBusControllerforSerialEEPROM)使用说明,及IP参考代码下载 | ||
+ | * Lattice Semi的[I2C主控制器](http://www.latticesemi.com/en/Products/DesignSoftwareAndIP/IntellectualProperty/ReferenceDesigns/ReferenceDesigns02/I2CMasterController)使用说明,及IP参考代码下载 | ||
+ | * Lattice Semi的[用于嵌入式功能块中的I2C从设备](http://www.latticesemi.com/en/Products/DesignSoftwareAndIP/IntellectualProperty/ReferenceDesigns/ReferenceDesigns02/I2CSlavePeripheralusingEmbeddedFunctionBlock)使用说明,及IP参考代码下载 | ||
+ | * Lattice Semi的[I2C从到SPI主的桥接](http://www.latticesemi.com/en/Products/DesignSoftwareAndIP/IntellectualProperty/ReferenceDesigns/ReferenceDesigns02/I2CSlavetoSPIMasterBridge)使用说明,及IP参考代码下载 | ||
+ | * FPGA4FUN上的[关于I2C的介绍及相应的Verilog代码资源](https://www.fpga4fun.com/I2C.html) | ||
+ | * FPGA4FUN上的I2C从设备的[[http://www.fpga4fun.com/files/I2Cslave1.zip|完整的代码]] |