I2C Master Read

Read data from I2C slave device or I2C slave device register

  • Library:
  • Simulink Coder Support Package for NXP FRDM-KL25Z Board/FRDM-KL25Z

Description

The I2C Master Read block reads serial data from an I2C slave device that is connected to the board. Using this block, you can read data from a specific register on the I2C slave device.

For more information on I2C communication, see Support I2C Communication.

Ports

Output

expand all

The block reads vector data from an I2C device on the board. The size of the data is the value that you specify in the Data size parameter.

Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double

When you select the Output error status parameter, the block configures an output port. The port on the block is labeled as Status, indicating that the block outputs the status of the read operation at the output port.

The block outputs the status as a uint8 value. Each value corresponds to a data transfer status.

Status valueStatus description
0SUCCESS
1BUSY
2ARBITRATION_LOST
4NO_ACKNOWLEDGE
8I2C_BUS_ERROR

Data Types: uint8

Parameters

expand all

Specify the I2C module on the board from which you want to read data from the I2C slave device.

Specify the I2C slave address from which you want to read the data. You can specify this address in hexadecimal format hex2dec(), for example, ‘hex2dec(‘20’)’.

The 2-byte ordering options are:

  • BigEndian - The most significant byte is sent first over the I2C bus.

  • LittleEndian - The least significant byte is sent first over the I2C bus.

When you select this parameter, the block reads data from the I2C slave register that you specify in the Slave register address parameter.

When you clear this parameter, the Send NACK at the end of data transfer and Remove stop bit at the end of data transfer parameters are displayed. Using these parameters, you can modify the read operation according to your requirements.

Specify the I2C register address from which you want to read the data.

Specify this address as an integer or in hexadecimal format by using hex2dec(), for example, ‘hex2dec(‘20’)’.

For more information on register read/write, see I2C Register Read/Write.

Dependencies

This parameter appears only when you select Enable register access parameter.

Specify the data size that you want to read from the I2C slave device for the selected data type.

Select the data type in which you want to read from the I2C slave device.

When you select this parameter, the I2C Master Read block sends a NACK (Not Acknowledge) bit to the slave device with the final byte.

When the slave device receives the NACK, it waits for a STOP condition from the I2C master block. The master block generates either a STOP condition to abort the transfer or a repeated START condition to start a new transfer.

When you clear this parameter, the I2C Master Read block sends an ACK (Acknowledge) bit to the slave device at the end of every byte. The ACK indicates that the I2C Master Read block is ready to read the next byte from the slave device.

Dependencies

This parameter appears only when you clear Enable register access parameter.

When you clear this parameter, the block sends a STOP condition. This condition indicates that the block has terminated the data transmission and that the I2C bus is free for any other I2C master block to initiate the new read/write operation.

When you select this parameter, the block sends another START condition followed by an address and read/write bit. The block sends any number of start conditions recursively. Such a repeated START condition allows write operations to the slave devices without releasing the bus. No other master block interrupts the operation.

Dependencies

This parameter appears only when you clear Enable register access parameter.

When you select this parameter, the block configures an output port. The port on the block is labeled as Status, indicating that the block outputs the status of the write operation at the output port.

The block outputs the status as a uint8 value. Each value corresponds to a data transfer status.

Status valueStatus description
0SUCCESS
1BUSY
2ARBITRATION_LOST
4NO_ACKNOWLEDGE
8I2C_BUS_ERROR

Specify how often the I2C Master Read block reads data from the I2C slave device. When you specify this parameter as-1, the block inherits its sample time based on the context of the block within the model.

Introduced in R2016b