Raspberry Pi SPI Kernel Driver Available for Download

Kernel driver for SPI for the Raspberry Pi to drive hardware inferface boards for IO expansion is nearly finished.

You can download the pre-compiled kernel with spi driver included here — just make a backup of your original kernel.img file on the boot partition of your SD card and replace it with this one.

http://gromit.cs.man.ac.uk/RaspberryPi/kernel.img

Power up the Raspberry Pi and log in.

type dmesg | grep spi and you should see

pi@raspberrypi:~$ dmesg | grep spi
in spi_init driver
in bcm2835_spi_probe
bcm2835_spi_probe base 0x20204000, remapped 0xcc80c000
in bcm2835_spi_reset
bcm2835_spi setbits wrote  0x00041030 to 0xcc80c000
bcm2835_spi clrbits wrote  0x00041000 to 0xcc80c000
bcm2835_spi bcm2835_spi.0: registered master spi0
in bcm2835_spi_setup
spi spi0.0: setup mode 0, 8 bits/w, 20000 Hz max –> 0
bcm2835_spi bcm2835_spi.0: registered child spi0.0
in bcm2835_spi_setup
spi spi0.1: setup mode 0, 8 bits/w, 20000 Hz max –> 0
bcm2835_spi bcm2835_spi.0: registered child spi0.1
bcm2835_spi_probe complete – 0

Now you need to switch over the pins from general IO to the SPI module. This should be in the pinctrl module, but in the meantime download http://gromit.cs.man.ac.uk/RaspberryPi/switchPinCtrl and execute it with root permissions.

sudo ./switchPinCtrl.

now try sending the a character to the spi with chipselect 0. e.g.

echo -n x > /dev/spidev0.0

Or with chipselect 1:

echo -n x > /dev/spidev0.1

(The -n tells echo not to send a newline character)

 

Please let us know how you get on. We want to hear your comments and bug reports.

The following will be changed in future releases

  • Alternative SPI modes (e.g. clock and data polarity/sample times)
  • Clock speed (dependent on reading clock speed from board)
  • GPIO pinmux/pinctrl
  • User defined enable/disable of SPI
  • Remove debugging statements

Source is available here:

http://gromit.cs.man.ac.uk/RaspberryPi/bcm2835_spi_Initial.patch

http://gromit.cs.man.ac.uk/RaspberryPi/switchPinCtrl.c

Advertisements

8 thoughts on “Raspberry Pi SPI Kernel Driver Available for Download

  1. Awesome news!The two commands you gave for sending a character are identical, did you mean to change a 0 to a 1 in the second example?

  2. This is what I’m looking for, great work!Any hints on how to change the setup in the source code? I see the constants definitions, e.g. "chip select active high", but they are never used, nor do I see a default value (I guess I’d be active low).. I’m trying to connect a nRF24L01+ and all this is quite new to me.

  3. I’ve not got the datasheet to hand, but if you find the linebcm2835_spi_setbits(bcm2835_spi, SPI0_CNTLSTAT, chipSelBits |SPI0_CS_ACTIVATE );and change it to bcm2835_spi_setbits(bcm2835_spi, SPI0_CNTLSTAT, chipSelBits |SPI0_CS_ACTIVATE| SPI0_CS_CSXACTHIGH)where X is the appropriate number then that will probably work. Clearly the proper way to do it is not to hard code it, but it might get you going this weekend and I’ll try and implement it properly next week — things have been busy getting the hardware finished. Do let me know how you get on.

  4. never mind the last comment, but another question would be how to read from the SPI. Can I simply perform a ‘cat /dev/spidev0.0’ ? Without attaching a device, this results in a ‘Message is too long’ error message from cat.

  5. never mind the last comment, but another question would be how to read from the SPI. Can I simply perform a ‘cat /dev/spidev0.0’ ? Without attaching a device, this results in a ‘Message is too long’ error message from cat.

  6. Hi, I use your spi kernel from this post. but I have a problem cause I need to be able to use my usb ports with usb-sticks and doest seems to be included usb block devices in your kernel. could you tell me how to solve this?br, zorce

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s