SPI and I2C Communication Using a CompactRIO

Updated Mar 16, 2021

Reported In

Hardware

  • NI-9401
  • NI-9402
  • CompactRIO Single-Board Controller
  • CompactRIO Controller

Issue Details

Is is possible to implement SPI or I2C communication using a CompactRIO?

Solution

Yes, it is possible. NI provides a free SPI and I2C driver API which uses the FPGA digital I/O lines to communicate with SPI or I2C devices.

When selecting the digital hardware there are three options to consider:
  • NI Single-Board RIO hardware works with both SPI and I2C drivers.
  • NI 9401 C Series module works best with SPI drivers.
  • NI 9402 C Series module works best with I2C drivers.

Additional Information

I2C communication requires the device to tri-state the DIO lines on the fly. The 9401 is unable to do this without external hardware. NI thus recommends the 9402 for I2C communication.

This library is installed using VIPM. If you are using LabVIEW 2010 or later, ensure to disable Mass Compile before installing the driver. Otherwise, a broken VI will appear in the library VIs.
Complete the following steps to disable Mass Compile:
  1. Open VI Package Manager.
  2. Select Tools and then Options.
  3. Remove the checkmark from the Mass Compile VIs After Package Installation checkbox.
Note: Support for this product is provided on the NI Developer Forums at forums.ni.com