minipixel
Posts: 3
Joined: Tue Apr 04, 2017 11:10 am

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

Mon Apr 16, 2018 4:51 pm

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 297 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 297 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

User avatar
joan
Posts: 13296
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

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

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 */

minipixel
Posts: 3
Joined: Tue Apr 04, 2017 11:10 am

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

Tue Apr 17, 2018 8:43 am

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?

User avatar
joan
Posts: 13296
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

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

Tue Apr 17, 2018 10:10 am

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.

mweetman2
Posts: 1
Joined: Thu Apr 12, 2018 11:35 am

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

Wed May 09, 2018 8:53 pm

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

HiassofT
Posts: 84
Joined: Fri Jun 30, 2017 10:07 pm

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

Thu May 10, 2018 1:09 pm

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

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 4 guests