I successfully drive a DAC via SPI using the spidev native SPI driver using a RaspberryPi3. The core portion of my code is as follows:

fd = open("/dev/spidev0.0", O_RDWR);
trstruct.tx_buf = (unsigned long)txarr;
ioctl(fd, SPI_IOC_MESSAGE(1), &trstruct);

It works ok, but timing is far from what I was expecting. Inspecting the SPI signals shows the following (top trace is chip select, mid trace is data and bottom trace is SCLK): enter image description here As we can see, the chip select is asserted low far before data transfer(about 6.5us earlier, and data transfer lasts just 1.9us). This behavior voids the benefits of using SPI at high speeds when multiple subsequent data transfers are needed.

Any idea how to speed up the chip select assertion low and to minimize its lasting low after data transfer is finished ?

Many thanks in advance, Marco


The lastest RPi Linux SPI driver controls the chip selects in software rather than letting the hardware drive the chip selects. That's probably the reason for the delay you are seeing. The driver probably does this as a consequence of allowing arbitrary GPIO to act as chip selects (rather than just those GPIO supported by the hardware).

You could search for an earlier RPI Linux SPI driver which did not have this feature.

Alternatively you could try using either of the bcm2835 or (my) pigpio libraries which use their own drivers which may or may not have this behaviour.

  • Many thanks Joan. I will try the two libraries you have indicated. Nov 17 '18 at 6:43

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.