6

I have a Raspberry Pi 3, and I would like to use it to communicate with an SPI device.

The pins from the SPI device have been connected to the appropriate headers on the board. Windows 10 IoT interacts with my device OK, using Windows.Devices.Spi classes from .NET.

Now I want to do same in Linux.

I am getting a "Message too long" error, from both cat /dev/spidev0.0 & and my own C++ code that uses open & ioctl calls to interact with that device (however in my application, it's interesting that open & port setup complete without errors).

Config.txt:

disable_overscan=1
hdmi_force_hotplug=1
hdmi_group=2
hdmi_mode=82
dtparam=spi=on
dtparam=audio=on
gpu_mem=128
dtoverlay=spi-bcm2835

uname -r: 4.9.41-v7+

lsb_release -a: Raspbian GNU/Linux 9.1 (stretch)

My device is connected to pins 19, 21, 23, 24, 25:

Enter image description here

Does Linux use the same pins for SPI as Windows 10 IoT?

asked Sep 13, 2017 at 13:09

3 Answers 3

4

It was a stupid error on my side.

SPI_IOC_MESSAGE ioctl call expects pointer to the first spi_ioc_transfer element in the argument.

I passed a pointer to pointer instead, because I saw many samples passing &array there, and I’ve forgot about this. I’ve fixed my C++ code, and it works now.

Meanwhile, cat /dev/spidev0.0 & command still prints Message too long. Apparently, that’s normal state of things.

answered Sep 13, 2017 at 14:05
1
  • 2
    Nice. Since this worked for you, remember to mark this answer as correct as soon as possible (I think that it's 48h) Commented Sep 13, 2017 at 14:34
4

According to Raspberry Pi Foundation:

The SPI master driver is disabled by default on Raspbian. To enable it, use raspi-config, or ensure the line dtparam=spi=on isn't commented out in /boot/config.txt, and reboot. If the SPI driver was loaded, you should see the device /dev/spidev0.0.

So, try to reboot your board after enabling SPI.

Peter Mortensen
2,0042 gold badges15 silver badges18 bronze badges
answered Sep 13, 2017 at 13:23
1
  • Yes, I’ve rebooted the board and I have both spidev0.0 and spidev0.1 under /dev/ Commented Sep 13, 2017 at 13:27
3

Since your error is "message too long", try increasing buffer size adding to /boot/cmdline.txt:

spidev.bufsiz=xxxxxxx

being xxxxxxx a number, ie: spidev.bufsiz=32768.

answered Sep 13, 2017 at 13:43
1
  • Edited, rebooted, same error. My messages are 5 bytes long. And the same error is returned when I’m sending even a single byte with SPI_IOC_MESSAGE ioctl call. Commented Sep 13, 2017 at 13:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.