I2C Master
Configure and communicate with I2C slave device
Libraries:
SoC Blockset /
Hardware Logic I/O
Description
The I2C Master block configures and communicates with an inter-integrated circuit communications (I2C) slave device connected to a field programmable gate array (FPGA). This block contains an I2C master controller with an AXI-Lite interface to perform the configuration.
The I2C Master block supports these features:
AXI4-Lite interface support for configuration and access
Single-master and multi-slave support
Support 7-bit and 10-bit address I2C slave devices
Burst mode support with a maximum burst size of 256 bytes
Support multiple transmission speed modes
An HDL-IP compatible model with code generation capability
The block uses the AXI-Lite interface to configure and create a control path interface to communicate with an I2C slave device. The hardware generated from the generation process contains an AXI-Lite register interface and two hardware interfaces, serial clock (SCL), and serial data (SDA). SCL and SDA connect the I2C Master block and the slave device.
Each port represented in the block is an AXI-Lite register, except the sdaIn, sclIn, scl, and sda ports. To communicate with a slave device, the AXI-Lite register interface configures the register information in the I2C Master block. This table contains the I2C Master AXI-Lite register information.
Register Address | Port and Register Name | Register Size in Bits | Operation Mode |
---|---|---|---|
0x100 | ctrlInf — Control information | 32 | Write |
0x104 | slvAddr — Slave address | 32 | Write |
0x108 | regAddr — Register address | 32 | Write |
0x10C | dataReg — Data register | 32 | Write |
0x110 | readDone — Read done register | 32 | Write |
0x114 | done — Done register | 32 | Write |
0x118 | rdy — Ready register | 32 | Read |
0x11C | respData — First response data register | 32 | Read |
0x120 | validData — Response data valid register | 32 | Read |
0x124 | statusReg — Status register | 32 | Read |
To perform read and write operations using the I2C Master block, you need to follow a proper sequence. This section provides information about the sequence flow for read and write operations.
Read Sequence
To read data from an external slave device:
Send the ctrlInf register information.
Send the slvAddr register information.
Send the regAddr register information.
Set the done register to
1
after sending one set of register information to the block and then set it to0
.Read the response data from the external slave device. After reading the data from the respData register, set the readDone register to
1
and then set it to0
immediately.Set the readDone register to
1
again, to read more than 4 bytes of data. After the read operation, set it to0
immediately.
In read sequence, one set of register information is a combination of ctrlInf, slvAddr, and regAddr registers.
Write Sequence
To write data to an external slave device:
Send the ctrlInf register information.
Send the slvAddr register information.
Send the regAddr register information.
Send the dataReg register that contains the data to write to the slave device register.
Set the done register to
1
after writing one set of register information to the block, and then set it to0
.Set the done register to
1
again, to write more than 4 bytes of data. After the write operation, set it to0
immediately.
In write sequence, one set of register information is a combination of ctrlInf, slvAddr, regAddr, and dataReg registers.