I am trying to configure my Raspberry Zero W SPI interface to communicate lsb-first. I've modified spidev_test.c, but when I run it, I get an error:

uint8_t lsb_first = 1;
ret = ioctl(fd, SPI_IOC_WR_LSB_FIRST, &lsb_first);
if (ret == -1)
    pabort("can't set lsbfirst");

can't set lsbfirst: Invalid argument

If I set it to zero, it works.

Does the Raspberry Pi not support lsb-first? And if so, why is this apparently not documented anywhere?

  • 2
    TBH I've no idea but as a workaround you can reverse the bit order in the byte you are sending and then transfer using the MSB code... Ugly 'hack' but if it keeps you on track...
    – user130616
    Mar 21 at 16:07
  • Yeah, I considered that. Fastest example I found was to define a look-up table. In this particular case, it's probably simpler just to change the firmware of the slave device (I wrote it). But I want to know if the Pi does actually lack this basic functionality. Mar 21 at 16:15
  • Can the coward who downvoted my question please tell me why? Apr 22 at 19:13

For something to be documented you need to read the documentation.

The main SPI device (GPIO 7-11) has no support for changing the bit order.

The auxiliary SPI device (GPIO 16-21) supports changing the bit order.


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.