Example SPI test

From wiki.emacinc.com
Revision as of 16:29, 21 February 2014 by Bserrano (talk | contribs)
Jump to: navigation, search
TODO: {{#todo:In Progress|Brian Serrano|oe 4,oe 5,md,InProgress,bs}}

This is a guide to the spi_test example project included in the EMAC OE SDK.

SPI (Serial Peripheral Interface) is a synchronous full duplex serial data communication standard used to interface many types of memory and I/O devices. SPI requires four lines per slave device connection, three of which are shared across the SPI bus. MISO, MOSI and SCLK are the three shared bus lines and chip selects (CSn) are used to determine which device is the target for communication.

This procedure provides an overview of how to compile and run the spi_test C example project. This is an example test interface for sending a transaction to an EMAC SPI device interface. It is only relevant if the EMAC SPI device interface is enabled for an external SPI device that is connected to the bus. It assumes familiarity with the C programming language and is intended to be used by experienced programmers who are looking to learn the EMAC SDK.

For more information about the SPI protocol see the following page: http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus

The spi_test project builds one executable: spi_test.

Opening, Building, and Uploading the Project Files

For information on opening the project from within Eclipse, please see, Importing the EMAC OE SDK Projects with Eclipse. Then, follow Using the EMAC OE SDK Projects with Eclipse for information on how to build, upload, and execute the example.

Alternatively, the Makefile can be used with the make command from the command-line to build and upload the example. For more information on this method, please see, Using EMAC OE SDK Example Projects.

Usage and Behavior

Hardware Requirements

The spi_test C example project will run on any EMAC carrier board which has an SPI interface (see also the EMAC SPI Programming page).

Using spi_test

The spi_test program is executed from the console. It takes three parameters.

root@emac-oe~:$ ./spi_test device length mosi
  • device: Name of the spi device node.
  • length: Length of spi transactions in bytes.
  • mosi: Hex value to be transmitted in hexadecimal.
root@emac-oe~:$ ./spi_test /dev/mcp3208 4 12ABCDEF

This command was run on an EMAC SoM-150ES carrier board. The results will appear in the terminal:

12   :  00  
AB   :  00
CD   :  00
EF   :  00


The spi_test C example project demonstrates how to use the SPI device. SPI enables the serial exchange of data between two devices, one called a master and the other called a slave. It operates in full duplex mode.