Example Code

Add 6 Digital Output Lines to 845x using SPI CS Lines

Code and Documents

Attachment

Example Overview:

The USB-845x devices have 8 general purpose DIO lines as well as the needed lines for I2C and SPI communication. For an application where more digital output is needed and SPI communication is not being used, the Chip Select (CS) lines can be programmed to behave as digital outputs using this subVI.

This is implemented using the SPI Scripting API, which allows us to explicitly set the digital value high or low for each of the 6 CS lines.

SPI_Scripting_CS_DO_BlockDiagram.png

Required Software and Hardware:

LabVIEW Base 2010 or newer

845x Driver 1.1.4 or newer

NI-8451 or 8452

Execution Instructions:

This VI is designed to be used as a subVI in a basic DIO application and included inside a while loop or for loop. Each time it executes it will create a script that sets a specific CS line to a specific logic level and run the script.

For a loopback test to verify this VI's functionality:

1. After plugging in your USB-845x device, open the NI Example Finder (LabVIEW > Help > Find Examples...) and browse to Hardware Input and Output > I2C and SPI > DIO Basic > Digital Line Read.vi example.

2. Choose the USB resource from the dropdown on the front panel and run the VI.

3. Connect a wire from CS0 terminal (pin 13) to the PO.0 terminal (pin 17). For a more complete pinout look here.

4. Open this VI and select the USB resource from the drop down on the front panel and run the VI.

5. Change the boolean value on the front panel of SPI_Scripting_CS_DO.vi and watch the indicator change on Digital Line Read.vi

Joey S.
Senior Product Manager, Software
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
rkmadse
Member
Member
on
So if basic SPI IS being used, but DIO lines are being utilized as CS lines could this still work? Or does the Streaming configuration wash out the ability to use SPI at all? I'm guessing when using SPI there is no other way to manually control the CS lines correct?
Contributors