I2C Master

Configure and communicate with I2C slave device

  • Library:
  • 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

  • 7-bit addressing support

  • Multiple transmission speeds support, which includes these modes:

    • Standard mode (up to100 kHz)

    • Fast mode (up to 400 kHz)

    • Fast-plus mode (up to 1 MHz)

  • Burst mode support with a maximum burst size of 16 bytes

  • 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 block enables you to perform simulation and generation processes separately. 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, scl, and sda ports. To communicate with the 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.

AddressPort and Register NameRegister Size in BitsOperation Mode
0x100ctrlInf — Control information

32

Write
0x104slvAddr — Slave address

32

Write
0x108regAddr — Register address

32

Write
0x10CdataReg — First data register

32

Write
0x110dataReg1 — Second data register

32

Write
0x114dataReg2 — Third data register

32

Write
0x118dataReg3 — Fourth data register

32

Write
0x11CuserRdy — User-ready register32Write
0x120done — Done register

32

Write
0x124rdy — Ready register32Read
0x128respData — First response data register32Read
0x12CrespData1 — Second response data register32Read
0x130respData2 — Third response data register32Read
0x134respData3 — Fourth response data register32Read
0x138validData — Response data valid register32Read

Ports

Input

expand all

Control information register that contains configuration information on how the block communicates with the slave device. Specify this value as a scalar, as described in this table. You can modify the configuration based on your requirement.

BitPurposeValue Description
0Set write or read mode.

To write to the slave-device register, set this value to 0. To read from the slave-device register, set this value to 1.

[2:1]Set the size of the slave-device register address.

If the slave-device register address size is:

  • One byte (8 bits), set this value to 00

  • Two bytes (16 bits), set this value to 01

  • Three bytes (24 bits), set this value to 10

  • Four bytes (32 bits), set this value to 11

[6:3]Set the data size of the slave-device register.

If the slave-device register supports:

  • One byte of data, set this value to 0000

  • Two bytes of data, set this value to 0001

  • Three bytes of data, set this value to 0010

  • Four bytes of data, set this value to 0011

  • Five bytes of data, set this value to 0100

  • Six bytes of data, set this value to 0101

  • Seven bytes of data, set this value to 0110

  • Eight bytes of data, set this value to 0111

  • Nine bytes of data, set this value to 1000

  • Ten bytes of data, set this value to 1001

  • Eleven bytes of data, set this value to 1010

  • Twelve bytes of data, set this value to 1011

  • Thirteen bytes of data, set this value to 1100

  • Fourteen bytes of data, set this value to 1101

  • Fifteen bytes of data, set this value to 1110

  • Sixteen bytes of data, set this value to 1111

7ReservedReserved

Data Types: uint8

Slave-address register that contains the address of the slave device, specified as a scalar.

Data Types: uint32

Specify the register address of the slave device as a scalar.

Data Types: uint32

First data register that the block uses to write the first 4 bytes of data to the slave-device register, specified as a scalar. This register includes the least significant bit (LSB).

Data Types: uint32

Second data register that the block uses to write the second set of 4 bytes of data to the slave-device register, specified as a scalar.

Data Types: uint32

Third data register that the block uses to write the third set of 4 bytes of data to the slave-device register, specified as a scalar.

Data Types: uint32

Fourth data register that the block uses to write the fourth set of 4 bytes of data to the slave-device register, specified as a scalar. This register includes the most significant bit (MSB).

Data Types: uint32

User-ready signal, specified as a Boolean scalar. When this value is 1 (true), the user is ready to read the response data from the block. When this value is 0 (false), the user is not ready to read the response data from the block.

Data Types: Boolean

Done signal, specified as a Boolean scalar. This value indicates the block when to read the AXI-Lite register information.

Set this value to 1 (true) after sending one set of register information to the block. The block reads the AXI-Lite register information only when you set this value to 1. Set this value to 0 (false) immediately after this operation.

One set of register information is a combination of ctrlInf (Control information), slvAddr (Slave address), regAddr (Register address), and dataReg, dataReg1, dataReg2, and dataReg3 (Data registers).

Data Types: Boolean

Input serial data, specified as a Boolean scalar. This port provides a serial data signal to the block from the slave device.

Dependencies

To enable this port, set the Type of model parameter to Simulation.

Data Types: Boolean

Output

expand all

Output serial clock, returned as a Boolean scalar. This port provides a serial clock signal from the block to the slave device.

Data Types: Boolean

Output serial data, returned as a Boolean scalar. This port provides a serial data signal from the block to the slave device.

Data Types: Boolean

Ready signal, returned as a Boolean scalar. When this value is 1 (true), the block is ready to accept the configuration data. When this value is 0 (false), the block is not ready to accept the configuration data.

Data Types: Boolean

First response data register that contains the first 4 bytes of data from the slave-device register, returned as a scalar. This register includes the least significant bit (LSB).

Data Types: uint32

Second response data register that contains the second set of 4 bytes of data from the slave-device register, returned as a scalar.

Data Types: uint32

Third response data register that contains the third set of 4 bytes of data from the slave-device register, returned as a scalar.

Data Types: uint32

Fourth response data register that contains the fourth set of 4 bytes of data from the slave-device register, returned as a scalar. This data includes the most significant bit (MSB).

Data Types: uint32

Control signal that indicates if the response data is valid, returned as a Boolean scalar. When this value is 1 (true), the response data from response data registers is valid. When this value is 0 (false), the response data from response data registers is not valid.

Data Types: Boolean

Parameters

expand all

Specify the model type.

  • To use this block for simulation purposes, set this parameter to Simulation.

  • To use this block for generation purposes, set this parameter to Generation. The generation process creates a hardware IP with AXI-Lite interface, SCL, and SDA interfaces.

Specify the speed mode as one of these values:

  • Standard Mode — Supports frequencies up to 100 KHz

  • Fast Mode — Supports frequencies up to 400 KHz

  • Fast Plus Mode — Supports frequencies up to 1 MHz

Extended Capabilities

Fixed-Point Conversion
Convert floating-point algorithms to fixed point using Fixed-Point Designer™.

Introduced in R2019a