Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

SPI on RPI



Has anyone successfully used SPI on an RPI on -current/evbarm (or more specifically on an RPI0W)?  If so, would you be able to share a code snippet for setting it up and sending some data through?

I made the spi device show up with a custom overlay a while ago:

$ dmesg | grep spi
[     1.000000] bcmspi0 at simplebus1: SPI
[     1.000000] bcmspi0: interrupting on icu irq 54
[     1.000000] spi0 at bcmspi0: SPI bus

And I did what seemed reasonable based on reading the spi(4) manpage, to send through some data of length slen bytes pointed at by sbuf:

	struct spi_ioctl_transfer spt;
	int fd, r;

        spt.sit_addr = 0;
	spt.sit_send = sbuf;
	spt.sit_sendlen = slen;

	fd = open("/dev/spi0, O_RDWR);
	r = ioctl(fd, SPI_IOCTL_TRANSFER, &spt);

But my test program simply stops responding after initiating the transfer.

I didn't configure SPI before use (assuming it would use default parameters), but I wouldn't have known how to do so any way as he manpage for spi(4) doesn't describe the values of the mode config parameter or the meaning of the address (in the source tree the former seem to be defined in sys/dev/spi/spivar.h, which is also referenced in spi(9), but AFAICS that header file isn't included in binary distributions).

I'm also not sure whether I should have activated the SPI pins in /etc/gpio.conf as I do for GPIO.

I'm running the latest -current/evbarm6hf kernel (as of yesterday) on an RPI0W. 

Many thanks,
Pouya


Home | Main Index | Thread Index | Old Index