Page 1 of 1

SPI delay between bytes is different for small and large transfers (spidev)

Posted: Mon Apr 16, 2018 4:51 pm
by minipixel
Hi,

I am investigating the SPI behaviour on Raspberry Pi 3 Model B. I am using spidev. One thing that keeps me awake at night is the following:
  • when performing a transfer of 95 bytes or less, I get a delay between each byte of around 1.5 of the SCLK period:
95_or_less.png
95_or_less.png (51.7 KiB) Viewed 570 times
  • when performing a transfer of 96 bytes of more, there is no delay between bytes:
96_or_more.png
96_or_more.png (50.63 KiB) Viewed 570 times
I have read multiple different forum posts on similar topics but did not get a conclusion on where this setting is comming from and how to control it (if possible at all).
In my application, I am trying to achieve:
1. to control either to make a delay between bytes or not, independent of the transfer size
2. to control the duration of the delay.
I guess No. 2 is more complicated than the No. 1.

Any help is appreciated.

Regards,
minipixel

Re: SPI delay between bytes is different for small and large transfers (spidev)

Posted: Mon Apr 16, 2018 5:16 pm
by joan
You might need to make a Linux SPI driver change (if the change is not present in the current driver).

I have the following line in the pigpio driver for the main SPI device. I don't remember who discovered this fix, just that it wasn't me.

Code: Select all

spiReg[SPI_DLEN] = 2; /* undocumented, stops inter-byte gap */

Re: SPI delay between bytes is different for small and large transfers (spidev)

Posted: Tue Apr 17, 2018 8:43 am
by minipixel
joan wrote:
Mon Apr 16, 2018 5:16 pm
You might need to make a Linux SPI driver change (if the change is not present in the current driver).

I have the following line in the pigpio driver for the main SPI device. I don't remember who discovered this fix, just that it wasn't me.

Code: Select all

spiReg[SPI_DLEN] = 2; /* undocumented, stops inter-byte gap */
Wow, this really helped. I have tested the latest pigpio library and I saw that this change is already included there. Thanks!
It's a pitty though that this is hardcoded in the driver. I would rather like to change the behaviour on-the-fly. Does anybody know what is the reset value for this setting?

Re: SPI delay between bytes is different for small and large transfers (spidev)

Posted: Tue Apr 17, 2018 10:10 am
by joan
You will need to check with the maintainer of the Pi Linux kernel SPI driver (perhaps user msperl, but that may be a faulty memory).

Just to note that pigpio is a userland driver so will still suffer random inter-byte gaps caused by reschedules.

Re: SPI delay between bytes is different for small and large transfers (spidev)

Posted: Wed May 09, 2018 8:53 pm
by mweetman2
Hi
Did you find a fix for this under spidev? I have the same issue, but see the delay with long buffers when calling writebytes or xfer/xfer2. There is no delay with buffers less than 0x10000 bytes in length, but I see a 1.5 bit time delay between bytes when buffers are 0x10000 byte in length or more.
Thanks

Re: SPI delay between bytes is different for small and large transfers (spidev)

Posted: Thu May 10, 2018 1:09 pm
by HiassofT
mweetman2 wrote:
Wed May 09, 2018 8:53 pm
Did you find a fix for this under spidev? I have the same issue, but see the delay with long buffers when calling writebytes or xfer/xfer2. There is no delay with buffers less than 0x10000 bytes in length, but I see a 1.5 bit time delay between bytes when buffers are 0x10000 byte in length or more.
That's probably the DMA "lite channel" limit. The data has to be split into less than 64k chunks as that's the maximum the DMA controller can do (on the "lite" channels) so a short delay between the chunks is to be expected.

so long,

Hias