VirtualBench: Master SPI With the DIO

製品と環境

このセクションは、サンプルの作成に使用された製品およびOSを反映します。

以下に示された製品を含め、NIのソフトウェアをダウンロードするには、ni.com/downloadsをご覧ください。

    ハードウェア

  • VirtualBench All-in-One Instrument

コードとドキュメント

添付

Description

Overview
This example automates the digital input output (DIO) channels to master SPI commands and performs a read.


[+] Enlarge Image

 

Steps to Run Program

    1. Download the example program on the right under downloads.
    2. In LabVIEW software, open the program by going to File » Open… and navigating to the file.
    3. Connect the VirtualBench device.
    4. Select the correct VirtualBench bus channel from the pull-down menu of the VirtualBench Bus Channel control. Set the clock rate, clock polarity, clock phase, and chip select polarity; specify the data to write
    5. Click the Run button to write and read data.
    6. The data acquired will display in the Results indicator.

 

Program Explained

 


[+] Enlarge Image

    • Initialize Session
      • The VirtualBench bus channel is passed into the SPI Initialize VI to initialize a new session on the SPI engine for the device.
      • A Boolean true constant is also passed into the VI to reset the device to default values.
    • Configure Instrument
      • Instrument and error information are passed into the SPI Configure Bus VI along with the clock rate, clock polarity, clock phase, and chip select polarity.
    • Perform Operation
      • Instrument and error information are passed to the SPI Write Read VI.
      • The data to write is also passed into the VI, and then the VI performs a write followed by a read.
      • The VI then outputs the data read to the indicator on the front panel.
    • Close Session
      • The instrument and error information are passed to the SPI Close VI. This closes the session and deallocates any resources for the next time a session is created with the instrument.
    • Handle Errors
      • Finally, the error information is passed into the Simple Error Handler VI. If an error has occurred, a dialog box will open to notify the user.

 

Additional Resources

 

VirtualBench Examples

NIコミュニティのサンプルコード交換のサンプルコードは、MIT Licenseによりライセンス供与されています。