element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Make Life Accessible
  • Challenges & Projects
  • Design Challenges
  • Make Life Accessible
  • More
  • Cancel
Make Life Accessible
Blog EyePrints - Post 6 - SPI communication
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: amgalbu
  • Date Created: 30 Apr 2016 8:12 AM Date Created
  • Views 571 views
  • Likes 1 like
  • Comments 0 comments
  • makelifeaccessible
  • eyeliner
  • spi interface
  • spidev
  • eyeprints
  • spi
  • make_life_accessible
Related
Recommended

EyePrints - Post 6 - SPI communication

amgalbu
amgalbu
30 Apr 2016

Previous posts

Post 1 - Introduction

Post 2 - Installing OpenCV - Prerequisites

Post 3 - Installing OpenCV

Post 4 - Installing Pygaze

EyePrints - Post 5 - Installing eye tracker

 

 

After some nights of hard thinking about pros and cons, I decided to make the three boards of this project to communicate through an SPI bus

The Serial Peripheral Interface Bus or SPI bus is a synchronous serial data link standard, named by Motorola, that operates in full duplex mode.  SPI is much simpler than I2C. Master and slave are linked by three data wires, usually called MISO, (Master in, Slave out), MOSI (Master out, Slave in), the SCLK clock line (sometimes called M-CLK), and an optional SS (Slave Select; sometimes known as the Chip Select or CS line or Chip Enable or CE line) is the slave select or chip select line.

 

image

 

In theory, The CS line is optional only if you have one slave, otherwise one or more SS lines are provided. In my case, the chip select line is not required since I’m going to send the same data in “broadcast” to both the NXP Freedom boards.

 

Usually the transfer sequence consist of driving the SS line low, sending X number of clock signals with the proper polarity and phase, then driving the SS line high to end the communication. As the clock signals are generated, data is transferred in both directions, therefore in a “transmit only” system the received bytes have to be discarded and in a “receive only” system a dummy byte has to be transmitted.

Many SPI-enabled ICs and Microcontrollers can cope with data rates of over 10MHz, so transfer is much faster than with I2C. Since it is synchronous communications, it is not limited to 8-bit words so you can send any message sizes with arbitrary content and purpose. The SPI interface does not require pull-up resistors, which translates to lower power consumption. The downside is that SPI normally has no addressing capability; instead, devices are selected by means of a SS signal which the master can use to enable one slave out of several connected to the SPI bus. If more than one slave exists, one chip select line is required per device, which can use precious GPIO lines on the Master.

 

Installing SPI on Raspberry Pi

To enable SPI on the Raspberry board, launche the raspi-config utility

 

$ sudo raspi-config

 

Then, select the “Advanced options” entry

image

 

And finally SPI

 

image

 

Click “Yes” to confirm that you want to enable SPI module. I also answered “yes” when asked whether I want to enable SPI interface by default so that the SPI driver is loaded automatically on boot

You can now reboot the Raspberry. At restart, check whether the SPI devices are there by typing

 

$ ls /dev

 

You should see the two SPI devices

 

image

 

If you can’t see the devices, may be you need to update the board to the latest firmware, as the latest has brought out the SPI controller. To do so I used Andrews Hexxeh rpi-update to do this.

 

sudo rpi-update


Once the updates are all completed., reboot your Raspberry.

 

sudo reboot


and now you should see spidev in /dev/ directory

The last part of this is to test the SPI signal. I'm going to download a test application: spidev_test.c

https://raw.githubusercontent.com/raspberrypi/linux/rpi-3.14.y/Documentation/spi/spidev_test.c


The test requires that MISO and MOSI pins are shorted.

 

image

 

Then, we need to edit the spidev_test.c file so it it uses the correct spidevice in the /dev/ folder.

 

nano spidev_test.c


scroll down and change the device to "spidev0.0".

 

image

 

Let's compile and run it

 

gcc spidev_test.c
sudo ./a.out


This is the result: so the SPI driver is actually working!

 

image

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube