I2c Slave
I2c Slave
write data
● Phillips® I2C-bus compliant 8
8
● User defined I2C slave address PAD Config reg #2 config
Config reg #1
scl 8
● Configurable number of 8-bit read/write configuration registers Config reg #0
up to a maximum of 128 oe
I2C SLAVE read
PAD CONTROLLER data
READ
Status reg #n
● Configurable number of 8-bit read-only status registers up to a MUX
sda
maximum of 128
Applications ro_flag
● Standard 2-wire comms between a wide range of I2C Generic name Description Type Valid range
peripherals, micro-controllers and COTs ICs.
num_config Number of integer 2 ≤ regs ≤ 128
configuration registers
Pin-out Description num_status Number of integer 2 ≤ regs ≤ 128
Status registers
slave_address 8-bit slave address of std_logic “0000000X”
Pin name I/O Description Active state
the device on the I2C vector to
clk in Synchronous clock rising edge bus (LSB is don't care) “1111111X”
reset in Asynchronous reset low
scl in I2C input SCL clock pin as per I2C General Description
specification
sda i/o I2C bi-directional SDA as per I2C
data pin specification The I2C_SLAVE IP Core is a Philips® I2C compliant slave interface
controller. The controller decodes the SCL and SDA bus signals and
ad_flag out Address register write flag pulse high converts them into a simple series of 8-bit read/write commands for
accessing a set of user-defined registers. These registers are defined as
wr_flag out Config register write flag pulse high
either configuration registers or status registers.
rd_flag out Config register read flag pulse high
Config registers provide general purpose read/write bits for the control of
ro_flag out Status register read flag pulse high external logic. Status registers are read-only and allow the state of
config out Configuration register data external pins to be monitored via the I2C interface. Both the config and
[num_config*8 - 1:0] output bits status bits are visible at the controller top-level ports.
status in External status register data The SCL port is an input driven by the I2C Master. The SDA port is
[num_status*8 - 1:0] input bits connected to a bi-directional tristate buffer. When the I2C controller is
inactive, both the SCL and SDA lines will be in a high impedance (high-Z)
state.
Note: The SCL and SDA pins should have external (or internal) pullups as
per the I2C specification.
ACK STOP
STOP
I2C Slave Controller Core
ACK
NO
The slave controller core is a state-machine that continually monitors the
D0
D1
D2
SCL clock frequency must have a ratio of 8:1 or greater. That is, the
following formula must be satisfied such that:
D3
D4
f CLK ≥ f SCL ∗ 8
D6
f SCL = I2C clock frequency ( Hz )
D7
ACK
ACK
ACK
To begin a data transfer, the state machine looks for a start command
A0
which is defined by a stable SCL high signal with a falling SDA line. On
1
receipt of a start command, the slave will latch the slave address and the
A1
R/W = '1'
REGISTER ADDRESS
REGISTER ADDRESS
A2
SLAVE ADDRESS
slave_address, then the controller will generate an acknowledge signal
A3
0 = Config register
1 = Status register
1 = Status register
then the controller will not acknowledge the master and it will revert back
A4
Once the controller has been addressed correctly, the master may send
one of two possible commands to the slave. These commands are either
A6
C/S
A7
STRT
ACK
ACK
RPT
Configuration and Status Register banks
0
0
ACK from Slave
R/W = '0'
SLAVE ADDRESS
If the I2C master writes to a register address that doesn't exist then
STRT
STRT
nothing will happen. Reading a register that doesn't exist will result in the
value 0xFF being returned on the I2C bus.
Figure 2: I2C command sequence for a register byte write and a register
byte read
The slave controller IP Core accepts standard I2C bus timing. However, An example VHDL test bench is provided for use in a suitable VHDL
in order to avoid spurious START and STOP commands being decoded simulator. The compilation order of the source code is as follows:
then the SDA line should only change on the SCL falling edge.
The SDA line should have a positive hold time (t_h) relative to the SCL 1. i2c_inbuf.vhd
falling edge. It is recommended that this hold time is equal to at least one 2. i2c_iobuf.vhd
system clock cycle. In addition, the SCL line should have a 50-50 duty 3. i2c_config_bank.vhd
cycle +/- 10%. 4. i2c_status_bank.vhd
5. i2c_slave_cont.vhd
The I2C timing specifications are shown in Figure 3 below. 6. i2c_slave.vhd
7. i2c_slave_file_reader.vhd
8. i2c_slave_bench.vhd
The VHDL test bench instantiates the i2c_slave component together with
SCL a file-reader module that reads the I2C bus signals from a text file. The
I2C slave address may be modified by changing the generic setting
slave_address on the slave controller component. The I2C clock
frequency can be modified by changing the t_period generic on the file
SDA reader component. The value t_period is a clock divider setting that
specifies the system clock to SCL clock ratio.
The input text file is called i2_slave_stim.txt and should be put in the
current top-level VHDL simulation directory.
t_h t_h
The I2C bus signalling is split into 4 phases on 4 consecutive lines. Each
line is comprised of two bits in the format 'A B' where 'A' specifies the
state of the SCL line and 'B' is the state of the SDA line. The values 'A'
and 'B' can either be specified as '0' (logic 0), '1' (logic '1') or 3 (tristate).
Figure 3: I2C bus timing specifications
As an example, in order to send a start command, the text file should
read:
Source File Description
01 # SCL = 0, SDA = 1
All source files are provided as text files coded in VHDL. The following 11 # SCL = 1, SDA = 1
table gives a brief description of each file. 10 # SCL = 1, SDA = 0
10 # SCL = 1, SDA = 0
Source file Description To send a single bit (in this case a '1') the text file may be written as:
i2c_slave_stim.txt Input stimulus text file
i2c_inbuf.vhd Input buffer 01 # SCL = 0, SDA = 1
01 # SCL = 0, SDA = 1
i2c_iobuf.vhd Bi-directional tristate buffer
11 # SCL = 1, SDA = 1
i2c_config_bank.vhd Configuration register bank 11 # SCL = 1, SDA = 1
The simulation generates the text file i2c_slave_out.txt which samples the
state of the SDA line on the rising SCL clock edge. The contents of this
file may be examined to verify the operation of the I2C slave controller.
The files required for synthesis and the design hierarchy is shown below:
● i2c_slave.vhd
○ i2c_slave_cont.vhd
○ i2c_config_bank.vhd
○ i2c_status_bank.vhd
○ i2c_iobuf.vhd
○ i2c_inbuf.vhd
Revision History