Documentation Home Page RT-LAB Home Page
Pour la documentation en FRANÇAIS, utilisez l'outil de traduction de votre navigateur Chrome, Edge ou Safari. Voir un exemple.

KXUSB910H_I2C_AsyncCtrl

Block

Mask

Description

This document describes the Keterex KX USB-910H I2C Controller block that allows an external I2C device, either a master or a slave, to read data from the model or write data to the model. Usage of this block requires a KX USB-910H adapter to be connected to a USB port of the target.

The block can operate as a master or as a slave. As described below, the master mode has additional configuration parameters and additional input. As I2C protocol is only using two wires, it cannot perform read and write operations at the same time. In master mode, the input is used to select if the device is sending data to an armed I2C slave device, or reading data from it. This input is not required in slave mode because it is the master that decides to either command a read or write operation.

The communication is handled by the asynchronous process that is responsible for the data exchange between the external device and the model. This asynchronous process is an independent executable that needs to be transferred to the target and is launched during model initialization. Although this asynchronous process code should cover most of the typical I2C read/write operations, it is the user responsibility to adapt it according to its application requirement. This file needs to be transferred to the target during model compilation as explained in the 'File transfer' section.

For more information on the KX USB-910H adapter or I2C communication, please refer to Keterex website.

Parameters

General Parameters

Adapter IDIdentifies which KX USB-910H adapter to control in the case where multiple adapters are present on the system. This ID must be 0 for the first adapter, 1 for the second adapter and so on.
ModeSpecifies the block operation mode (Master or Slave).
Output widthSpecifies the width of the output data port. If no output data is required, this field must be set to -1.
Bit rate (kbps)Specifies the I2C bit-rate. In I2C communication, this rate must be the same for the master and the slave devices. The unit is in kilobits per second (kbps).
SCL timeout (ms)This function sets the I2C SCL low timeout period of the adapter. The I2C interface will automatically free the I2C bus if the SCL signal remains low for a period exceeding this timeout value. If the requested time is ? 0.0, the timeout feature is disabled (i.e. set to infinity). The unit is in milliseconds (ms).
LSB firstInstructs the adapter to transmit and receive all data bytes least-significant-bit first. Otherwise, the most-significant-bit is transmitted/received first.
Free bus detectionInstructs the adapter to detect the bus as free if SCL remains high for 3.3 clock periods.
Abort on errorInstructs the adapter to abort the operation if an expected value is incorrect.
Retry of arbitration lostInstructs the adapter to retry if an operation terminates due to loss of arbitration.
Executable name

Specifies the name of the executable file of the asynchronous application that handles the low-level communication transactions.



Note: at this time, the only precompiled executable available for I2C control is 'AsyncI2C'. The name should be placed between single quotes (').



Inputs


Data ready: This input can be used to control the rate at which the data inputs are sampled.

Data input: Data connected to this port will be transferred to the external I2C device. The width of this port determines how much bytes can be transferred during a single data transfer. It is important to note that this input can only transmit data in bytes format.

Master mode: This input is only available when the block is configured into master mode. It instructs the master device used to send data to an armed I2C slave device or to read data from it. The operation will be performed according to the following values:

Master modeDescription
0Read data from the I2C slave and apply this data to block outputs
> 0Write block inputs to the I2C slave

Outputs

Status: This output is a 4-wide vector that contains status and error codes from the asynchronous process. Typically, error codes should be 0 and the status should oscillate between 0 and 2.The bus can be de-multiplexed as shown below:

IndexDescription
0Data transmit error
1Master mode receive error (only effective into master mode)
2Rata receive error
3Data receive status

Data output: The data sent by the external I2C device will be applied to this output bus. The width of this bus is defined by the 'Output width' parameter described above. Additional bytes received during a single data transfer will be discarded.

File Transfer

As explained in the 'Description' section, the asynchronous process executable must be transferred to the target and compiled before loading the model. This is done through RT-LAB by settings the correct parameters in the 'File' pane of the model. If you have any problem with the file transfer, refer to the example model. Here is an example:

Characteristics and Limitations

Inputs: The block can only transmit 8 data bits per input, per single data transfer.

Outputs: If the block receives more bytes than the configured width of the output port during a single data transfer, additional data will be discarded.

Configuration: The block bit rate, 'LSB first' and 'Free bus detection' parameters must match the configuration of the external I2C device.

Pull-up resistors: I2C pull-up resistors are always activated. It means that 2.2k resistors are connected between the I2C pins (SCL and SDA) and the configured I/O voltage. It must also be activated on the external I2C device.

Direct FeedthroughNo
Discrete sample timeNo
XHP supportNo
Work offlineNo

OPAL-RT TECHNOLOGIES, Inc. | 1751, rue Richardson, bureau 1060 | Montréal, Québec Canada H3K 1G6 | opal-rt.com | +1 514-935-2323