I've got a position sensor that I need to read out via SPI from the Raspberry Pi. The sensor is a MLX90316, that requires interbyte spacing in the SPI message. Typically, I need something like this (recorded from a Cortex M3 which reads the sensor without problems):
As you can see, there is interbyte spacing between the individual bytes. The MLX90316 needs a bit of time to fill the last 2 MISO bytes with the sensor value, after seeing the
0x55 in the first byte. When, I use the spidev driver on the Pi, it generates messages like:
While the MOSI part looks a lot similar, the sensor does not get enough time to fill the answer in the last two bytes. So I definitely need the interbyte spacing.
My current solution is to bitbang and use my own enable line to generate the packages with the interbyte spacing as needed. See https://gist.github.com/steviethecat/29d5e0e91dca0080a20c21fda33d7064 for the code. While this works, the load on the Pi is around 45% CPU.
Is there a more efficient solution that is accomplishes the same? I'd rather use the regular spidev library. I did notice a
.pad option, but modifying that does not seem to have any effect on the interbyte spacing.