Main Content

I2C Controller Write

Write data to I2C peripheral device or I2C peripheral device register

Add-On Required: This feature requires the Simulink Support Package for Raspberry Pi Hardware add-on.

  • I2C Controller Write block

Libraries:
Simulink Support Package for Raspberry Pi Hardware / Communication

Description

Write data to an I2C peripheral device or an I2C peripheral device register. Using this block, you can also write data to a specific register on the I2C peripheral.

For more information on I2C communication, refer to Support I2C Communication and Raspberry Pi I2C Interface. To open the pin map of the Raspberry Pi board, click the View pin map.

Ports

Input

expand all

The input port write data to the I2C peripheral device or I2C peripheral device register.

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

Output

expand all

Output port to display error status. For more information, see Output error status.

Dependencies

This port appears only when you select the Output error status parameter.

Data Types: uint8

Parameters

expand all

Select the specific board that you are using. Changing the board updates the pin choices that you get.

Specify the I2C module on the Raspberry Pi® hardware to communicate with SPI peripheral. For more information on the Raspberry Pi pin mapping and modules that hardware boards support, click View pin map.

Enter the I2C peripheral device address to which you want to write the data. The I2C peripheral device address is a 7-bit address.

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

Select the byte ordering that your I2C peripheral supports.

The two byte ordering options are:

  • BigEndian — The most significant byte is written first over the I2C bus. This option is the default option.

  • LittleEndian — The least significant byte is written first over the I2C bus.

Select this check box to write data to a specific I2C peripheral register.

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 write operation according to your requirements. For more information, I2C Register Read/Write

Enter the peripheral device register address to which you want to write the data.

Dependencies

This parameter is enabled only when you select the Enable register access parameter.

When you select this parameter, the I2C Controller Write 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 Write 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 clear this parameter, the I2C Controller Write block sends an ACK (Acknowledge) bit to the peripheral device at the end of every byte. The ACK indicates that the I2C Controller Write block is ready to read the next byte from the peripheral device.

Dependencies

This parameter appears only when you clear the 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 the I2C bus is free for any other I2C controller block to initiate the 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

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

Select this option to display the output error status. 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
8BUS_ERROR
16BUS_NOT_IN_USE

Version History

Introduced in R2017a