Search by Tags

How to use SPI library in VCSharp

 
Article updated at 08 Jun 2018
Compare with Revision


Attention: this is a legacy library and thus not supported by Toradex anymore. We recommend that you use the new libraries for all Toradex modules. Please see the Toradex CE Libraries and Code Samples for up-to-date information.

This article aims to help the developer, to use Toradex SPI library in VCSharp.

SPI (Master mode)

SPI Library provides easy access to SPI interface available on Toradex computer modules. SPI (Serial Peripheral Interface) library configures the SSP (Synchronous Serial Port) unit to be used as a standard SPI interface.

Some of the devices that can be interfaced using SPI interface are:

  • Temperature sensors
  • Memories like Flash and EEPROM
  • Audio codecs
  • DAC (Digital to Analog Converter)
  • and many more..

SPI library download

For general information about SPI, please have a look at this article.

We provide free SPI Library including sample demo source codes.

NOTE: Please use compatible SPI Channel if you want to maintain compatibility between different Colibri modules.

Interfacing 12 bit SPI based DAC

This tutorial demonstrates the use of Toradex SPI library to interface MCP4921 12-bit digital to analog converter (DAC) with Colibri T20 module (any module can be used) and Evaluation board V3.1A to generate Square, Sine, Sawtooth and Triangle Waveforms.

Hardware setup

The following pin connections have to be made between MCP4921 12-bit DAC and Evaluation Board v3.1A for running the SPI Library on Colibri T20.

MCP4921 SPI Signal Evaluation Board V3.1A (Silkscreen)
DAC_CS Chip Select (CS) SODIMM_86 / SSP_FRM
DAC_SCK Serial Clock (SCLK) SODIMM_88 / SSP_SCLK
DAC_SDI Master Out Slave In (MOSI) SODIMM_92 / SSP_TXD
+5V (2.7V - 5.5V operational range) - 3.3V
GND - GND

Demo application

This application demonstrates how to use Toradex SPI library to read/ write operation on SPI chip.

  • Download demo source code from here.
  • Download and Install .NET Compact Framework on device from here.
  • Navigate to Solution Explorer in visual studio, Right Click on vcsharp_spi_demo > Properties > Devices.
  • Uncheck Deploy the Latest version of the .NET Compact Framework (including Service Packs).
  • Navigate to Solution Explorer in visual studio, Right Click on vcsharp_spi_demo > Properties > Build.
  • Check Allow unsafe code.
  • Build and deploy solution.
  • On the Colibri Module go to My Device > Program Files > vcsharp_spi_demo. Double click on the vcsharp_spi_demo.exe to run the application.

Follow the steps as mentioned below:

  • Select the waveform from dropdown box.
  • Click on the set button.
  • Connect Oscilloscope at the output pin of DAC to see the waveform.

Screenshot of Demo application running.


Oscilloscope output showing Square- wave output from DAC.


Oscilloscope output showing Sine- wave output from DAC.


Oscilloscope output showing Sawtooth- wave output from DAC.


Oscilloscope output showing triangle- wave output from DAC.