I progress...but....This code works with Linksprite OS (ubuntu12.11) but not here.
root@pcduino3nano:~/SPI/Pcduino_SPI# python3 Pcduino_SPI_example.py
SPI device: /dev/spidev0.0
SPI speed: 12000000
SPI bits per word: 8
IOC_MESSAGE: 1075866368
IOC_TRANSFER: b'h\x9e\x98\xb6\x00\x00\x00\x00\x88\x97\x92\xb6\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Traceback (most recent call last):
File "Pcduino_SPI_example.py", line 32, in <module>
test(IODIRB, 0b00000000)
File "Pcduino_SPI_example.py", line 27, in test
spi.transfer([OPCODEW], 0)
File "/root/SPI/Pcduino_SPI/Pcduino_SPI.py", line 497, in transfer
fcntl.ioctl(self.handle, self._IOC_MESSAGE, spi_ioc_transfer)
OSError: [Errno 22] Invalid argument
Maybe the problem is here?
The pin mode with LS OS :
10 : 1
11 : 2
12 : 0
13 : 2
With your's 'in' ou 'out':
10 : out
11 : in
12 : in
13 : in
I can send my python code if you want.
Thx a lot
EDIT :
With spi_test.c
With LinkSprite Ubuntu 12.11 ('00 00 00' because nothing between MISO and MOSI)
ubuntu@ubuntu:~/SPI$ ./spidev_test
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00
With Armbian
root@pcduino3nano:~/SPI/Pcduino_SPI# ./spidev_test
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)
can't send spi message: Invalid argument
Aborted
EDIT2 :
If I change spidev.h and add 1 line, the spidev_test.c is ok (but not my python )
BUT...if I add this line in LinkSprite Ubuntu12 the test fails !!!
Anybody have an answer ????
/usr/include/linux/spi/spidev.h
the struct in there is already written as you proposed:
struct spi_ioc_transfer {
__u64 tx_buf;
__u64 rx_buf;
__u32 len;
__u32 speed_hz;
__u16 delay_usecs;
add -> __u16 interbyte_usecs;
__u8 bits_per_word;
__u8 cs_change;
__u32 pad;
/* If the contents of 'struct spi_ioc_transfer' ever change
* incompatibly, then the ioctl number (currently 0) must change;
* ioctls with constant size fields get a bit more in the way of
* error checking than ones (like this) where that field varies.
*
* NOTE: struct layout is the same in 64bit and 32bit userspace.
*/
};