Professional Documents
Culture Documents
cn
1. Introduction
As we all know, in consumer electronics, telecommunications and industrial electronics
nowadays, there are often many similarities between seemingly unrelated designs. For example,
nearly every system includes:
Some intelligent control, usually a single-chip microcontroller
General-purpose circuits like LCD drivers, remote I/O ports, RAM, EEPROM, or data
converters
Application
oriented circuits such as digital tuning and signal processing circuits for radio and
video systems, or DTMF generators for telephones with tone dialing.
To exploit these similarities to the benefit of both systems designers and equipment
manufacturers, as well as to maximize hardware efficiency and circuit simplicity, Philips
developed a simple bi-directional 2-wire bus for efficient inter-IC control. This bus is called the
Inter IC or I2C bus.
At present, Philips IC range includes more than 150 CMOS and bipolar I2C bust compatible
types for performing functions in all three of the previously mentioned categories. All I2C bus
compatible devices incorporate an on-chip interface which allows them to communicate directly
with each other via the I2C bus. This design concept solves the many interfacing problems
encountered when designing digital control circuits. [1]
In our project, we use I2C bus as the connect port to communicate with peripheral equipment.
We design an I2C slave in FPGA and make a program in PC to simulate the I2C master such as
SCM or MCU which will really control the FPGA in the future.
So in this paper, the principle and the operation of I2C bus will be introduced. Also the design
of I2C slave in FPGA and I2C master in PC will be discussed.
http://www.paper.edu.cn
is sampled during the high period of SCL; therefore, the SDA line may be changed only during the
low period of SCL and must be held stable during the high period of SCL. A transition on the SDA
line while SCL is high is interpreted as a command (see START and STOP signals).[2]
http://www.paper.edu.cn
Example 2
Read a byte of data from an I2C memory device.
Slave address = 0x4E
Memory location to read from = 0x20
I2C sequence:
1) Generate start signal
2) Write slave address + write bit
3) Receive acknowledge from slave
4) Write memory location
5) Receive acknowledge from slave
6) Generate start signal
7) Write slave address + read bit
8) Receive acknowledge from slave
9) Read byte from slave
10) Write no acknowledge (NACK) to slave, indicating end of transfer
11) Generate stop signal
-3-
http://www.paper.edu.cn
8 bits address
datain and dataout
SCL
I2C
Interface
Master
Registers for
Input Part
Input
Registers for
Process Part
Process
Registers for
Output Part
Output
SDA
Slave Core
Figure 4 : Block Diagram of I2C Slave Core:
In our design, only 8 bits data after the R/W signal will be regard as the memory address so that
master can read or write several registers from one input address.
Following is the operation sequence:
In the master writer case, the sequence is:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
http://www.paper.edu.cn
12.
13.
14.
15.
.
.
Master receives the data_n and sends a stop signal.
Output
serially
Idle
N
Receive 8 bits
And device address right ?
Send ACK
Read bit is
1?
Send 8 bits ?
Receive 8
bits ?
Send ACK
Read bit is
1?
Receive ACK
Address + 1
Wait for
memory address
N
Sda output
1?
N
Y
Receive 8
bits ?
Idle
Y
Send ACK
To test if the slave core works, an I2C master module is coded in verilog. The master read or
writes four serial registers in four serial addresses once time. We use ncverilog to do the
-5-
http://www.paper.edu.cn
simulation, the master write the data to the register first and then read the data from the
corresponding register to see if the data is the same.
Following is the waveform after simulation:
As we introduced above, the master should write a start address before writing and reading data.
The slave core receives the mem_AdrS first and receives the wr_data while the WRmemS occurs.
After that the address adds one automatically and waits the next WRmemS to receive the new
data.
-6-
http://www.paper.edu.cn
The slave core also receives the address first and prepares the data for master to read while the
RDmemS occurs. After that the address also adds one automatically and waits the next RDmemS
to prepare the new data.
-7-
http://www.paper.edu.cn
The bottom Initialize will pull up all the sda and scl line to initialize the I2C bus.
The bottom Write or Read will write or read Byte Num data to the address from the Start
Address. Byte Num means how many bytes the master will write or read.
When Write, master will get the data which to be write from the specifically txt file and write
them to the registers in FPGA.
When Read, master will read the data from the registers in FPGA and save them into the
specifically txt file.
The bottom Set 0 or Set 1 will set zero or one to any Bit of the register whose address is Start
Address.
The bottom Read All will read all the registers and display their values on the edit block of each
address.
The bottom Write All will write the data which input into each edit block to corresponding
address.
Follow figure shows the Read All operation:
-8-
http://www.paper.edu.cn
Figure 11: Read All Register Values Using I2C Master Software
5. Conclusion
In the paper, the principle of I2C bus is introduced detailedly. Also the design both I2C slave and
master are presented. The I2C slave core is tested not only in software by the simulation but also
in hardware by really connect to the PC which works like an I2C master device. The whole
communication through I2C bus is very helpful to anyone want to use this simple 2-wire bus and
useful in IC design.
Reference
[1] Philips Semiconductors (2000) The I2C-Bus Specification
[2] Richard Herveille (2003) I2C Master Core Specification Open Cores
[3] Wenyu Xia (2003) Digital system Design Tutorial --- Verilog
[4] Zhi Liu, JIngyi Yang (2003) Development and Application of I2C Simulation Software Kit Based on Parallel
Ports
[5] Wen Zhang (2002) Test of Simulation I2C Bus by PC Parallel Ports
-9-