0

so i need to set the bits per word to other than the deafult (which i think is 8)

import spidev

spi = spidev.SpiDev()
spi.open(0,1)

spi.bits_per_word = 8

This compiles no problem but when i set it to anything higher i get an error

Traceback (most recent call last):
  File "/home/pi/Desktop/PY/spi.py", line 8, in <module>
    spi.bits_per_word = 12
OSError: [Errno 22] Invalid argument

Which is very weird because if i set it to something lower than 8 an error says it must be in the range of 8 to 32 which is what i did earlier

Traceback (most recent call last):
  File "/home/pi/Desktop/PY/spi.py", line 8, in <module>
    spi.bits_per_word = 4
TypeError: invalid bits_per_word (8 to 32)
0

spidev will use the underlying Pi's Linux SPI driver. The Pi's SPI hardware supports 8 bits only on the main SPI device (spi0.x). The auxiliary SPI device (spi1.x) supports a range of bits (1 to 32). However I don't know if this is supported by the Linux SPI driver.

It seems likely you will have to bit bang the SPI protocol.

As an aside the pigpio SPI driver does support a different number of bits on the auxiliary SPI.

2
  • Even with pigpio the main SPI is only 8 bits? – DrakeJest Feb 25 at 19:11
  • Yes, that is a hardware limitation. – joan Feb 25 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.