VIM3 GPIO "WiringPI" SPI

Hello, we would like to use SPI via wiringPi.

#include
#include <errno.h>
#include <wiringPiSPI.h>
#include <unistd.h>

// channel is the wiringPi name for the chip select (or chip enable) pin.
// Set this to 0 or 1, depending on how it’s connected.
//static const int CHANNEL = 1;
static const int CHANNEL = 0;

int main()
{
int fd, result;
unsigned char buffer[100];

std::cout << “Initializing” << std::endl ;

// Configure the interface.
// CHANNEL insicates chip select,
// 500000 indicates bus speed.
fd = wiringPiSPISetup(CHANNEL, 500000);

std::cout << "Init result: " << fd << std::endl;

while(true)
{
buffer[0] = 0x55;
wiringPiSPIDataRW(CHANNEL, buffer, 1);
sleep(5);
}
}

By executing this program we get the message:

Unable to open SPI device: No such file or directory

We tried to load spi:

khadas@Khadas:/boot$ sudo gpio load spi
[sudo] password for khadas:
gpio: Unable to load/unload modules as this Pi has the device tree enabled.
You need to run the raspi-config program (as root) and select the
modules (SPI or I2C) that you wish to load/unload there and reboot.

sudo ls -l /dev/spi*
ls: cannot access ‘/dev/spi*’: No such file or directory

Is it possible to enable SPI without raspi-config?

regards from Norway
Kwklaus

The SPI is not enabled by default, you have to enable it in dts and rebuild the kernel.

1 Like