I2C Master Write
Write data to I2C slave device or I2C slave device register
Libraries:
Simulink Coder Support Package for NXP FRDM-K64F Board
Description
The I2C Master Write block writes data to an I2C slave device that is connected to the board. Using this block, you can write data to a specific register on the I2C slave device.
For more information on I2C communication, see Support I2C Communication.
Ports
Input
Data — Data that you want to write to the I2C slave device
scalar | vector
Data Types: int8
| uint8
| int16
| uint16
| int32
| uint32
| single
| double
Output
Status — Status of the write operation
scalar
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 write operation at the output port.
The block outputs the status as a uint8
value.
Each value corresponds to a data transfer status.
Status value | Status description |
---|---|
0 | SUCCESS |
1 | BUSY |
4 | NO_ACKNOWLEDGE |
Data Types: uint8
Parameters
I2C module — I2C module to write data
0
(default) | 1
Specify the I2C module on the board from which you want to write data to the I2C slave device.
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 using hex2dec()
, 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
When you select this parameter, the block writes data to 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 write operation according to your requirements.
Slave register address — The I2C slave register address to write data
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 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.
Send NACK at the end of data transfer — Option to send Not Acknowledge bit at the end of data transfer
off (default) | on
When you select this parameter, the I2C Master Write 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 Write block sends an ACK (Acknowledge) bit to the slave device at the end of every byte. The ACK indicates that the I2C Master Write block is ready to read the next byte from the slave device.
Dependencies
This parameter appears only when you clear Enable register access parameter.
Remove stop bit at the end of data transfer — Option to remove STOP bit at the end of data transfer
off (default) | on
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 master 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 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.
Output error status — 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 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 value | Status description |
---|---|
0 | SUCCESS |
1 | BUSY |
4 | NO_ACKNOWLEDGE |
Version History
Introduced in R2016b
See Also
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
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: .
You can also select a web site from the following list:
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érica Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)