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?

Soonts
  • 198
  • 1
  • 1
  • 10

3 Answers3

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,004
  • 2
  • 15
  • 18
rsp
  • 622
  • 1
  • 6
  • 16
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.

Soonts
  • 198
  • 1
  • 1
  • 10
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.

Luis Diaz
  • 473
  • 4
  • 8