superpat999
Posts: 15
Joined: Fri May 25, 2012 12:46 pm

Official raspbian distribution -- SPI devices?

Wed Jul 18, 2012 2:28 pm

Hi,


I am having problems with creating spi devices. (I wish to drive an SPI GLCD).

From Chris Boot's blog:-
3. Using SPI or I2C

The kernel above includes my SPI and I2C drivers for Raspberry Pi.

The SPI driver exposes two device files (/dev/spidev-0.0 and /dev/spidev-0.1), one for each cable select line (CE0 and CE1 on RPi). Look in the /usr/include/linux/spi/spidev.h header for how to drive this properly. There are also Python bindings available and I’m sure there are others available for other languages too. If you want to bind a kernel SPI device driver to an SPI chipselect line, you’ll have to edit the source and build your own kernel. Sorry, but that’s how it works in 3.2.

The I2C driver creates a Linux I2C bus just as any other I2C bus driver would. To use it from userspace you’ll want to load the i2c-dev module and play with /dev/i2c-0. If you want to use kernel I2C device drivers you can bind them from userspace without a rebuild, e.g.:

echo tmp102 0x48 > /sys/class/i2c-adapter/i2c-0/new_device
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
I have installed the latest raspbian,
(Linux raspberrypi 3.1.9+ #168 PREEMPT Sat Jul 14 18:56:31 BST 2012 armv6l GNU/Linux)

I commented out the blacklist entries for i2c and spi from /etc/modprobe.d/raspi-blacklist.conf i.e.

#blacklist spi-bcm2708
#blacklist i2c-bcm2708

Rebooted, and did a modprobe i2c-dev, I now see from lsmod

Code: Select all

root@raspberrypi:/# lsmod
Module                  Size  Used by
i2c_dev                 6115  0 
snd_bcm2835            21485  0 
snd_pcm                82208  1 snd_bcm2835
snd_seq                59808  0 
snd_timer              21905  2 snd_seq,snd_pcm
snd_seq_device          6920  1 snd_seq
snd                    57668  5 snd_seq_device,snd_timer,snd_seq,snd_pcm,snd_bcm2835
snd_page_alloc          5383  1 snd_pcm
evdev                   8922  0 
spi_bcm2708             4815  0 
i2c_bcm2708             3818  0 
and I now have two ic2 devices showing in /dev:- /dev/i2c-0 /dev/i2c-1

HOWEVER --- I do not get /dev/spidev-0.0 and /dev/spidev-0.1 "exposed" at all. There does not seem to be any spi modules to insert.

I would be extremely grateful if some kind person could offer a solution to my problem.

many thanks

regards

Patrick

superpat999
Posts: 15
Joined: Fri May 25, 2012 12:46 pm

Re: Official raspbian distribution -- SPI devices?

Wed Jul 18, 2012 3:43 pm

Hi
Googling around the net revealed another location for the SPI devices:-
On my Pi:-
root@raspberrypi:/# find /sys/bus | grep spi

Code: Select all

/sys/bus/platform/devices/bcm2708_spi.0
/sys/bus/platform/drivers/bcm2708_spi
/sys/bus/platform/drivers/bcm2708_spi/bcm2708_spi.0
/sys/bus/platform/drivers/bcm2708_spi/module
/sys/bus/platform/drivers/bcm2708_spi/uevent
/sys/bus/spi
/sys/bus/spi/uevent
/sys/bus/spi/devices
/sys/bus/spi/devices/spi0.0
/sys/bus/spi/devices/spi0.1
/sys/bus/spi/drivers
/sys/bus/spi/drivers_probe
/sys/bus/spi/drivers_autoprobe
So the devices are there but not in /dev.

How do I use them? Can I use them ( spi0.0 and spi0.1 )

P

marsman2020
Posts: 72
Joined: Sun May 20, 2012 11:26 pm

Re: Official raspbian distribution -- SPI devices?

Wed Jul 18, 2012 6:27 pm

You need to load the 'spidev' module to get userspace spi device access, in the same way the i2c-dev module provides userspace i2c access.

Try "modprobe spidev".

superpat999
Posts: 15
Joined: Fri May 25, 2012 12:46 pm

Re: Official raspbian distribution -- SPI devices?

Wed Jul 18, 2012 7:05 pm

You need to load the 'spidev' module to get userspace spi device access, in the same way the i2c-dev module provides userspace i2c access.

Try "modprobe spidev".
I would if I could, but there is NO spidev.ko (AFAIK)

regards

P

pholy
Posts: 46
Joined: Sun Jun 24, 2012 11:29 pm

Re: Official raspbian distribution -- SPI devices?

Thu Jul 19, 2012 12:37 am

You are right, the spidev module was not compiled. You (or somebody) will have to do a make menuconfig and be sure to set the CONFIG_SPI_SPIDEV to m. It is in a section called SPI PROTOCOL MASTERS. If that is all that is changed from a previous kernel compile I don't think it will take too long, but from scratch it will take from 6 to 9 hours depending on your SD card speed.

This probably should be raised with whoever is doing official builds if /dev/spi/* is required for using spi in any sensible fashion. I'm sure it was an oversight.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5502
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Official raspbian distribution -- SPI devices?

Sun Jul 22, 2012 9:50 pm

I've pushed out a build with CONFIG_SPI_SPIDEV enabled. You can get it from rpi-update (or probably the new bleeding edge firmware repo). Let me know if SPI is now good.

asb
Forum Moderator
Forum Moderator
Posts: 853
Joined: Fri Sep 16, 2011 7:16 pm
Contact: Website

Re: Official raspbian distribution -- SPI devices?

Sun Jul 22, 2012 9:58 pm

dom wrote:I've pushed out a build with CONFIG_SPI_SPIDEV enabled. You can get it from rpi-update (or probably the new bleeding edge firmware repo). Let me know if SPI is now good.
Yes, it includes that:
https://github.com/asb/firmware/commits/debian

See http://www.raspberrypi.org/phpBB3/viewt ... 66&t=12170 for information on this repository

superpat999
Posts: 15
Joined: Fri May 25, 2012 12:46 pm

Re: Official raspbian distribution -- SPI devices?

Tue Jul 24, 2012 4:01 pm

Hi,

Thanks for the new build. I have installed it and I now have spidev's in /dev.

Unfortunately, there will be a hiatus, I had a huge outpouring of the "Magic Smoke" from my GLCD module and PIC interface board.I plugged a 12V PS into the card instead of a 5V one, (same jack) :oops:

By a bit of luck the PI was not connected at the time.

I haven't had such a display of smoke and popping and banging since 1973, when I touched my chrome wrist watch band down on the back plane pins of a PDP11-20, whilst I was setting the core memory strobe timings. What upset my customer, was that it was working when I arrived, (I was only doing a PM), it took two days, and a big bag of chips, to get it working again.

I have dug through the junk pile and found another GLCD, a T6963C type this time, which I have wired to a MCP23S17, SPI to parallel i.c., and will also soon have a new buffer board ready for the Raspberry.

cheers

Patrick

bhensley
Posts: 7
Joined: Tue Jun 26, 2012 7:18 pm

Re: Official raspbian distribution -- SPI devices?

Thu Jul 26, 2012 1:32 am

For those that might be struggling with getting SPI working in any shape or form. I've written a nice little blog explaining how to get SPI working and tested on your Raspberry Pi. Check it out.

http://www.brianhensley.net/2012/07/get ... ry-pi.html


Cheers,

Brian Hensley
www.brianhensley.net

User avatar
engineerbynight
Posts: 3
Joined: Fri Jul 27, 2012 2:32 am

Re: Official raspbian distribution -- SPI devices?

Fri Jul 27, 2012 2:41 am

FYI... I worked through all of the suggestions in this thread with little success on Raspbian.

But, I was able to get SPI running on Raspbian using other means... I have detailed in this tutorial - http://www.instructables.com/id/Prelimi ... g-with-a-/

Feedback is greatly appreciated. I'm new to embedded Linux, so I'm sure there are some improvements that could be made. Plus, I still need to add some pics, hookup info, etc.

Return to “Raspberry Pi OS”