主要内容

I2C Master Write

Write data to I2C slave device or I2C slave device register

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

  • I2C Master Write block

Description

TheI2C Master WriteBlock将数据写入连接到板的I2C从设备。使用此块,您可以将数据写入I2C从设备上的特定寄存器。

有关I2C通信的更多信息,请参阅Support I2C Communication.

Ports

输入

expand all

数据Types:int8|uint8|INT16|uint16|INT32|uint32|single|double

Output

expand all

When you select the输出错误状态parameter, the block configures an output port. The port on the block is labeled asStatus,表明该块在输出端口输出写操作的状态。

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

Status value Status description
0 SUCCESS
1 忙碌的
2 仲裁_lost
4 NO_ACKNOWLEDGE
8 I2C_BUS_ERROR

数据Types:uint8

Parameters

expand all

在板上指定要将数据写入I2C从设备的板上的I2C模块。

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

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

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.

选择此参数时,该块将数据写入您在Slave register addressparameter.

当您清除此参数时,在数据传输结束时发送nackRemove stop bit at the end of data transferparameters are displayed. Using these parameters, you can modify the write operation according to your requirements.

Specify the I2C slave register address to which you want to write the data.

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

有关注册读/写的更多信息,请参阅I2C注册读/写.

Dependencies

This parameter appears only when you selectEnable register accessparameter.

When you select this parameter, theI2C Master Write块带有最终字节将nack(不承认)位发送到从设备上。

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.

当您清除此参数时,I2C Master Write块在每个字节的末尾将ACK(确认)位发送到从设备上。ACK表明I2C Master Writeblock is ready to read the next byte from the slave device.

Dependencies

This parameter appears only when you clearEnable register accessparameter.

当你清楚这个参数,发送一个年代TOP condition. This condition indicates that the block has terminated the data transmission and the I2C bus is free for any other I2C master 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 slave devices without releasing the bus. No other master block interrupts the operation.

Dependencies

This parameter appears only when you clearEnable register accessparameter.

When you select this parameter, the block configures an output port. The port on the block is labeled asStatus,表明该块在输出端口输出写操作的状态。

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

Status value Status description
0 SUCCESS
1 忙碌的
2 仲裁_lost
4 NO_ACKNOWLEDGE
8 I2C_BUS_ERROR

Version History

Introduced in R2016b

See Also