1

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);
txarr[0]=0xAA;
txarr[1]=0x01;
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

asked Nov 16, 2018 at 18:20

1 Answer 1

1

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.

answered Nov 16, 2018 at 18:53
1
  • Many thanks Joan. I will try the two libraries you have indicated. Commented Nov 17, 2018 at 6:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.