So one of the phases in my project is connecting the Raspberry Pi to a micro-controller that has many Pulse Width Modulation (PWM) signals. Since the Raspberry doesn’t have the number of PWM signals I need to control i’m going to do so through SPI. This post is the ‘how to’ on getting your SPI signals outputting from your Raspberry Pi. More blogs to come later to show you more details.
sudo apt-get update
sudo apt-get upgrade
While that is updating lets talk a little bit of SPI background knowledge is needed in order to get this working. First off Serial Peripheral interface (SPI) is made up of 4 wires normally. It is a standard that was designed by Motorola for use with their micro controllers. If you’re interested in learning more about SPI i’ve added the Wikipedia link. Here is what a standard SPI setup looks like, multiple slaves is optional.
SS – Slave Select (Beagleboard community calles this Chip Select (CS))
MOSI – Master Out Slave In
MISO – Master In Slave Out
CLK – Clock
sudo apt-get install git
Now lets download his tool and install change who has access to read/write the tool.
sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update
sudo chmod +x /usr/bin/rpi-update
Once this is done you can run it by calling the following command. (mine took a while).
*NOTE – while I was doing this I ran out of space on my 4GB drive. I figured I wasn’t really low on space and when I checked it I found my windows tool originally only made me a 2GB partition. There are many ways to do this, but I used GPARTED to expand my space to the real 4GB. It’s a live CD…
So once the updates are all completed. I rebooted my Pi.
sudo shutdown -h now
Unplug the power and plug it back in. And when I rebooted I went to my /dev/ directory and found my spidev devices!
The last part of this is to test the SPI signal. I’m going to download spidev_test.c
wget http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/spi/spidev_test.c -O spidev_test.c
Next we want to short the MISO and MOSI pins. Located as GPIO 9 & GPIO 10 as seen below.
We want to edit the spidev_test.c file so it it uses the correct spidevice in our /dev/ folder.
scroll down and change the device to “spidev0.0” and then save it by pressing the Ctrl+O to save and Ctrl+X to exit. lets compile this thing and run it now.
If you see this it’s working.
If you see this it’s not working.
For more information on how to control your SPI with python try checking out my post for how to do so on the beagleboard xm. Many have found it useful and i’m sure you will too. Python controlling SPI on the Beagleboard XM
Above is a picture of my Tektronix Mixed Domain Oscilloscope (MDO) testing out a SPI signal on a Beagleboard XM. Great piece of test equipment!