Checking SPI on Raspberry Pi

In my previous post, I described how to get SPI working on my Raspberry Pi. Now I wanted to check if it actually works.

I found a useful description on the web, but used only the second part about “testing”:

Given that the linux kernel module dealing with SPI is loaded, there is a small test application written in C that you need to download:

pi@raspberrypi ~ $ wget\;a=blob_plain\;f=Documentation/spi/spidev_test.c -O spidev_test.c

In spidev_test.c, change the following line

static const char *device = "/dev/spidev1.1";
static const char *device = "/dev/spidev0.0";
Now compile the C source code using gcc:
gcc spidev_test.c -o spidev_test
Run the test application:
pi@raspberrypi ~ $ sudo ./spidev_test
spi mode: 0 
bits per word: 8
max speed: 500000 Hz (500 KHz) 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00
Now connect the MISO and MOSI pins and execute this test application again:
pi@raspberrypi ~ $ sudo ./spidev_test
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)
40 00 00 00 00 95 
F0 0D
Looks good! This is what we expect.

Getting SPI working on the Raspberry Pi

The good thing about the web is, that you find thousands of answers to a specific question, but the really hard task is to find out which ones are “outdated” and which ones are the “state-of-the-art” way to do it. This is especially true when the question deals about an issue that is relatively new, and when there is a lot of work in progress around the issue by various people and groups.

I want to communicate with the RF module (with the TI CC1101) using SPI, so there is the need to get it working on my Raspberry Pi. After trying out several things I found on the web, it seems that the solution is quite easy:

You just need to remove the ‘blacklist’ entries from raspi-blacklist.conf.

sudo vi /etc/modprobe.d/raspi-blacklist.conf


Just comment out the two lines and reboot the system.

After the system is up again, use the command lsmod to show the status of the modules in the linux kernel:

pi@raspberrypi ~ $ lsmod
Module Size Used by
snd_bcm2835 15846 0 
snd_pcm 77560 1 snd_bcm2835
snd_page_alloc 5145 1 snd_pcm
snd_seq 53329 0 
snd_seq_device 6438 1 snd_seq
snd_timer 19998 2 snd_pcm,snd_seq
snd 58447 5 snd_bcm2835,snd_timer,snd_pcm,snd_seq,snd_seq_device
spidev 5224 0 
leds_gpio 2235 0 
led_class 3562 1 leds_gpio
spi_bcm2708 4510 0 
i2c_bcm2708 3759 0

You should now see the modules spi_bcm2708 and i2c_bcm2708. You should also see two device files in your /dev folder:

pi@raspberrypi ~ $ ls /dev | grep spi

Difficulties …

In my last blog post, I wrote that I “Somehow need to get RF module fit onto a breadboard”. In the meanwhile the Adafruit Pi Cobbler Breakout Kit arrived and was easy to solder, although I am not very experienced in that.
The RF module arrived with two lines of connector headers. So far so good, but: The spacing between the connector headers is about 0.5”, and for this reason it is not possible to directly plug it into the breadboard, which has a spacing of 1.0”. I tried to solder some connector cables to the connector headers, but this actually is very difficult, especially with my limited experience, and I think this kind of connection is also not very robust 😦

BTW: When I tried to change the orientation of the antenna, it just broke …

I will try to order some other kind of RF module with a more suitable spacing of the connector headers.

New RF Hardware


CC1101The “new” RF hardware has arrived, ordered from China (Shenzen) online at After 14 days I got two pieces of this module, for about €15 (including shipping). You can see the TI CC1101 in the middle, the antenna and the oscillator. In contrast to the RFBee, this module does not have a uC or a serial interface. It just has the pure pins to control the CC1101: SI, SO (GDO1), SCLK1, CSn, GDO0 and GDO2 and of course the pins for power supply. The next step will be to get it working with the Raspberry Pi’s GPIO. Somehow need to get this fit onto a breadboard.