I2C Master Read
Read data from I2C slave device or I2C slave device register
Simulink Support Package for Raspberry Pi Hardware / Communication
Read serial data from an I2C slave. Using this block, you can also read data from a specific register on the I2C slave device.
To open the pin map of the Raspberry Pi board, click View pin map button.
Data — Data output port to read data from the I2C slave device
The output port to read data from an I2C slave device. The size of the data that the port emits is based on the Data size (N) parameter.
Status — Status of the read operation
Output port to display error status. For more information, see Output error status.
This port appears only when you select the Output error status parameter.
Board — Specific board used for I2C communication
Pi 2 Model B (default) |
Model B Rev1 |
Model B Rev2 |
Model B+ |
Pi 3 Model B |
Pi 3 Model B+ |
Pi Zero W
Select the specific board that you are using. Changing the board updates the pin choices that you get.
Slave address — I2C slave device address
10 (default) | scalar
Enter the I2C slave device address from which you want to read data. You can specify this address in hexadecimal format hex2dec(), for example, hex2dec(‘20').
Slave byte order — Byte order supported by the I2C slave device
BigEndian (default) |
Select the byte ordering that your I2C slave supports.
The two byte ordering options are:
BigEndian— The most significant byte is read first over the I2C bus. This option is the default option.
LittleEndian— The least significant byte is read first over the I2C bus.
Enable register address — Option to enable reading from the register on I2C slave register
on (default) | off
Select this check box to enable reading data from a specific register on the I2C slave device.
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 read operation according to your requirements.
Slave register address — I2C slave device register address to read data
0 (default) | scalar
Enter the slave device register address from which you want to read the data.
Specify this address as an integer or in hexadecimal format
hex2dec(), for example, hex2dec(‘20’).
This parameter is enabled only when you select the Enable register access parameter.
Data type — Data type to read from I2C slave device
uint8 (default) | int8 | int16 | uint16 | int32 | uint32 | single | double
Select the data type to read from I2C slave device.
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 Read 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 Read block sends an ACK (Acknowledge) bit to the slave device at the end of every byte. The ACK indicates that the I2C Master Read block is ready to read the next byte from the slave device.
This parameter appears only when you clear the 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 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 slave devices without releasing the bus. No other master block interrupts the operation.
This parameter appears only when you clear Enable register access parameter.
Data size (N) — Data size to read from the I2C slave device
1 (default) | scalar
Enter the data size that you want to read from the I2C slave device for the selected data type.
Output error status — Option to display the error status during data transmission
off (default) | on
Select this option to display the error status during data transmission.
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 read 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|
Sample time — Time frequency at which block reads data
0.1 (default) | scalar
Specify how often this block reads the data from the I2C slave. Enter a value greater than zero.