Documentation Home Page Cell Monitoring Device Emulation Add-On for NI VeriStand Home page
Pour la documentation en FRANÇAIS, utilisez l'outil de traduction de votre navigateur Chrome, Edge ou Safari. Voir un exemple.

How to Integrate an External I2C or SPI Slave Device

Certain cell monitoring devices can communicate with externally connected circuits via I2C or SPI protocols over GPIO lines. These external circuits, which act as I2C/SPI slaves, can be sensors, analog multiplexers, serial-to-parallel converters, and more. Although physical GPIO lines are absent in an emulated environment, it is possible to simulate the I2C/SPI slave as an external model on the target CPU and interface it with the emulated device on the FPGA. Communication is established through VeriStand channels instead of traditional I2C or SPI protocols. This guide provides an overview of the necessary project configuration to add the slave model and the command sequence to run during execution.

ExternalDevice-Simple.png
Integration of an external I2C or SPI slave device on the real time target.

Because the communication occurs on the CPU, the data transfer speed between the external slave and the emulated cell monitoring device is limited by the execution rates of both the external model and the CMDE Add-On.

Project Configuration

  1. Check Compatibility

    • Ensure the emulated cell monitoring device supports WRCOMM and STCOMM commands. Documentation on supported commands for each Device type can be found in this Wiki space.

  2. Add External Model

    • Create a model of the external circuit and add it to the VeriStand project. Refer to Integrating and Executing Models for detailed instructions. The model interface should include:

      • Two inputs to receive COMM Register data from the emulated cell monitoring device:

        • Input 1: Control bits (ICOMx[3:0] and FCOMx[3:0])

        • Input 2: Data bits (Dx[7:0])

      • Two outputs to write data to the COMM Register of the emulated cell monitoring device:

        • Output 1: Control bits (ICOMx[3:0] and FCOMx[3:0])

        • Output 2: Data bits (Dx[7:0])

  3. Map Signals

    • In the VeriStand Editor, connect the signals between the external model and the cell monitoring device:

      • Map the WRCOMM Command and WRCOMM Data device channels to the inputs of the external model.

      • Map the outputs of the external model to the STCOMM Reply Command and STCOMM Reply Data device channels.

ExternalSensorConnections.PNG
  1. Connect SPI Master

    • Connect the SPI Master to the target DIO channels to establish SPI communication with the emulated device.

  2. Run Model

    • Save and deploy the VeriStand project.

Command Sequence

During execution, send the following sequence of commands from the SPI Master to the emulated device:

  1. WRCOMM

    • Data transmitted by the WRCOMM command is stored in the COMM Register of the emulated cell monitoring device. These values are continually written to the WRCOMM Command and WRCOMM Data channels, and subsequently received by the external model through the mapped input channels. Note that in a real system, the COMM Register values are transmitted to the I2C/SPI slave device only after the STCOMM command is received.

  2. STCOMM

    • When the STCOMM command is received, the emulated device reads the response written to the STCOMM Reply Command and STCOMM Reply Data channels by the external model. These values are stored in the COMM Register of the emulated device.

  3. RDCOMM

    • The SPI Master reads the values stored in the COMM Register.

 

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