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
Description
TheI2C Master WriteBlock将数据写入连接到板的I2C从设备。使用此块,您可以将数据写入I2C从设备上的特定寄存器。
有关I2C通信的更多信息,请参阅Support I2C Communication.
Ports
输入
数据
— Data that you want to write to the I2C slave device
scalar | vector
数据Types:int8
|uint8
|INT16
|uint16
|INT32
|uint32
|single
|double
Output
Status
— Status of the write operation
scalar
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 auint8
value. 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
I2C模块
- I2C模块编写数据
0
(default) | 1
在板上指定要将数据写入I2C从设备的板上的I2C模块。
Slave address
— The I2C slave address to which you want to write data
10
(default) |integer between 0 and 127
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’)’.
Slave byte order
— The byte ordering that your I2C slave device supports
BigEndian
(default) |LittleEndian
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.
Enable register access
— Option to write to a specific I2C slave register
on (default) | off
选择此参数时,该块将数据写入您在Slave register addressparameter.
当您清除此参数时,在数据传输结束时发送nack和Remove stop bit at the end of data transferparameters are displayed. Using these parameters, you can modify the write operation according to your requirements.
Slave register address
- I2C从寄存器地址写数据
0
(default) |integer between 0 and 255
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.
在数据传输结束时发送nack
- 在数据传输结束时发送未确认位的选项
off (default) | on
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.
Remove stop bit at the end of data transfer
— Option to remove STOP bit at the end of data transfer
off (default) | on
当你清楚这个参数,发送一个年代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.
输出错误状态
— Option to display the error status during data transmission
off (default) | on
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 auint8
value. Each value corresponds to a data transfer status.
Status value | Status description |
---|---|
0 |
SUCCESS |
1 |
忙碌的 |
2 |
仲裁_lost |
4 |
NO_ACKNOWLEDGE |
8 |
I2C_BUS_ERROR |
Model Examples
Version History
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
您还可以从以下列表中选择一个网站:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- AméricaLatina(Español)
- Canada(English)
- United States(English)
欧洲
- Belgium(English)
- 丹麦(English)
- Deutschland(德意志)
- España(Español)
- Finland(English)
- 法国(Français)
- 爱尔兰(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- 挪威(English)
- Österreich(德意志)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)