Main Content

I2C Controller Read

Read data from I2C peripheral device or I2C peripheral device register

Add-On Required: This feature requires the Embedded Coder Support Package for STMicroelectronics STM32 Processors add-on.

  • I2C Controller Read block

Libraries:
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32F4xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32F746G-Discovery
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32F769I-Discovery
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32F7xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32G4xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32H7xx Based Boards (Single-core)
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32L475VG-Discovery (B-L475E-IOT01A)
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32L4xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32L5xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32U5xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32WBxx Based Boards
Simulink Coder Support Package for STMicroelectronics Nucleo Boards / Common

Description

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

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

Ports

Output

expand all

The port 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

The port outputs the status of each read request as mentioned in the following table:

Return status codes

StatusDescription
0SUCCESS
1BUSY
2ARBITRATION_LOST
4NO_ACKNOWLEDGE
8BUS_ERROR
16BUS_NOT_IN_USE

Dependencies

To enable this port, select the Output error status parameter.

Data Types: uint8

Parameters

expand all

Specify the I2C module on the board to read data from the I2C peripheral device.

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.

Select the peripheral address source of I2C controller.

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

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

When you unselect this parameter, the Send no acknowledgement at the end of the transfer and Remove stop bit at the end of data transfer (Repeated start) parameters are displayed. Using these parameters, you can modify the read operation according to your requirements.

Select the register address source of I2C controller.

Dependencies

To enable this parameter, select Enable register access address mode parameter.

Specify the I2C register address 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

To enable this parameter, select Enable register access address mode parameter.

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

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

When the parameter is not selected, 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 Controller 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 peripheral devices without releasing the bus. No other Controller block interrupts the operation.

Dependencies

To enable this parameter, deselect the Enable register access address mode parameter.

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

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

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

Dependencies

To enable this parameter, deselect the Enable register access address mode 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 Controller Read block reads data from the I2C peripheral device. When you specify this parameter as-1, the block inherits its sample time based on the context of the block within the model.

You configure Timeout to be the maximum time (in seconds) to wait to complete a read operation.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.