12 Comments

  1. [...] I enabled the SPI device on my Rasp­berry PI, I wanted to drive some LED Mod­ules. Thanks to Scott Gib­son this was quite [...]

  2. 趣味の電子工作 » GPIO制御

    [...] Neophob  SPI [...]

  3. TT
    TT January 15, 2013 at 16:18 . Reply

    I am pretty new to programming. I have a device which I want to connect to the RPi using SPI. I tried out the spi_devtest.c and it works. But the SPI frame of the slave device requires 24 bits. I have searched high and low and have not been able to find a solution. I tried changing the number of bits per word but that does not work. I wonder if I would have to just send 3 bytes instead of 24 bits. In that case, I don’t know how to send 3 bytes without the chip select going inactive after each word. Any help would be greatly appreciated.

  4. TT
    TT January 16, 2013 at 22:09 . Reply

    nevermind, i figured it out. thanks anyways :)

  5. yvesined
    yvesined May 8, 2013 at 08:22 . Reply

    That was a quite awesome tutorial guys! Thank you. Is it possible to set digital GPIO Pins with this library (for example the CSN Pin that is recommened for SPI)?
    Greets, yvesined.

  6. Tom Hodder
    Tom Hodder July 24, 2014 at 15:18 . Reply

    After shorting the pins, I get the following output;

    $ sudo ./spidev_test
    spi mode: 0
    bits per word: 8
    max speed: 10000000 Hz (10000 KHz)

    EE FF

  7. Anteino
    Anteino November 8, 2014 at 03:45 . Reply

    When compiling the spidev_test.c it gives me a shitload of compile errors:

    root@raspberrypi:/home/pi/LEDServer# gcc spidev_test.c -o spidev_test
    spidev_test.c: In function âtransferâ:
    spidev_test.c:60:13: error: âSPI_TX_QUADâ undeclared (first use in this function)
    spidev_test.c:60:13: note: each undeclared identifier is reported only once for each function it appears in
    spidev_test.c:61:5: error: âstruct spi_ioc_transferâ has no member named âtx_nbitsâ
    spidev_test.c:62:18: error: âSPI_TX_DUALâ undeclared (first use in this function)
    spidev_test.c:63:5: error: âstruct spi_ioc_transferâ has no member named âtx_nbitsâ
    spidev_test.c:64:13: error: âSPI_RX_QUADâ undeclared (first use in this function)
    spidev_test.c:65:5: error: âstruct spi_ioc_transferâ has no member named ârx_nbitsâ
    spidev_test.c:66:18: error: âSPI_RX_DUALâ undeclared (first use in this function)
    spidev_test.c:67:5: error: âstruct spi_ioc_transferâ has no member named ârx_nbitsâ
    spidev_test.c: In function âparse_optsâ:
    spidev_test.c:172:12: error: âSPI_TX_DUALâ undeclared (first use in this function)
    spidev_test.c:175:12: error: âSPI_TX_QUADâ undeclared (first use in this function)
    spidev_test.c:184:12: error: âSPI_RX_DUALâ undeclared (first use in this function)
    spidev_test.c:186:12: error: âSPI_RX_QUADâ undeclared (first use in this function)
    spidev_test.c: In function âmainâ:
    spidev_test.c:204:18: error: âSPI_IOC_WR_MODE32â undeclared (first use in this function)
    spidev_test.c:208:18: error: âSPI_IOC_RD_MODE32â undeclared (first use in this function)

    I’ve done everything exactly like you said except that I used the 2014-09-09-wheezy-raspbian.zip. And because the edge bleed kernel from Chris Boot was not available anymore I reverted to olf firmware with: sudo rpi-update 8234d5148aded657760e9ecd622f324d140ae891. Could you give me advise on this? It seems that no environmental variables are declared in the program/system, what can I do to solve this? Create them manually?

    1. Anteino
      Anteino November 8, 2014 at 03:53 . Reply
  8. Richard Boardman (@uxrick)
    Richard Boardman (@uxrick) February 14, 2015 at 23:54 . Reply

    I came across this post looking for a fix to RPI problems with the more recent kernel upgrade (3.18)

    There is one other step to the above that you need to do:

    Add “dtparam=spi=on” to your /boot/config.txt and reboot.

    https://raspberrypi.stackexchange.com/questions/27073/firmware-3-18-x-breaks-i2c-spi-audio-lirc-1-wire-e-g-dev-i2c-1-no-such-f?newreg=d5f1e383852548aa9ec8158b694371f9
    http://www.raspberrypi.org/forums/viewtopic.php?p=675658#p675658

  9. bacha
    bacha May 29, 2015 at 00:22 . Reply

    FYI

    With MISO and MOSI shortened, I was able to get reliable tests between 3,815 and 62,499,999 Hz.

    Speeds equal to or above 62.5 MHz consistently gave this output:

    7F 7F 7F 7F 7F 7F
    20 00 00 00 00 4A
    7F 7F 7F 7F 7F 7F
    7F 7F 7F 7F 7F 7F
    7F 7F 7F 7F 7F 7F
    6F 56 5F 77 5D 56
    78 06

    The sweet spot of 62.5 MHz can be traced to the BCM2835 ARM Peripherals documentation (https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf footnote 5, page 20) which states the SPI clock runs (by default at max speed) at 125 MHz, which is the exact double of 62.5 MHz.

    Why it’s “only” capable of running at half the speed of the 125 MHz I do not understand.
    My initial thought was it must because it’s doing both the reading and the writing, but SPI is full duplex.
    Maybe some bright fellow could help shedding some light on this? :)

Leave a Reply

%d bloggers like this: