SPI delay between bytes

Hello,

I noticed a delay between the bytes/words (about 4µs) while sending SPI frames as illustrated here:

I couldn’t figure out the reason of it. Is it not possible to send the bytes continuously without pausing the SCLK between the bytes? is this behaviour because of the SPI driver? if yes could you suggest a SPI transfer function/driver.

Used functions:

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
static const char *device = "/dev/spidev2.0";
uint8_t tx[] = {
	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
	0x40, 0x00, 0x00, 0x00, 0x00, 0x95,
	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
	0xF0, 0x0D,
};
uint8_t default_rx[ARRAY_SIZE(tx)];

void SPI_init()
{	
	speed =1000000; //10Mhz
	bits = 8;

	fd = open(device, O_RDWR);
	if (fd < 0)
		pabort("can't open device");

	 // spi mode
	ret = ioctl(fd, SPI_IOC_WR_MODE32, &mode);
	if (ret == -1)
		pabort("can't set spi mode");

	ret = ioctl(fd, SPI_IOC_RD_MODE32, &mode);
	if (ret == -1)
		pabort("can't get spi mode");

	 //bits per word
	ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
	if (ret == -1)
		pabort("can't set bits per word");

	ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
	if (ret == -1)
		pabort("can't get bits per word");

	 // max speed hz
	ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
	if (ret == -1)
		pabort("can't set max speed hz");

	ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
	if (ret == -1)
		pabort("can't get max speed hz");

}			
					
static void SPI_transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len)
{
	int ret;

	struct spi_ioc_transfer tr = {
		.tx_buf = (unsigned long)tx,
		.rx_buf = (unsigned long)rx,
		.len = len,
		.delay_usecs = delay,
		.speed_hz = speed,
		.bits_per_word = bits,
	};

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 1)
		pabort("can't send spi message");

}

int main ()
{
	SPI_init();
	SPI_transfer(fd, tx, rx, ARRAY_SIZE(tx));
}

Device Tree:

&ecspi3 {
	status = "okay";

	mcp258x0: mcp258x@0 {
		compatible = "microchip,mcp2515";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_can_int>;
		reg = <0>;
		clocks = <&clk16m>;
		interrupt-parent = <&gpio5>;
		interrupts = <2 IRQ_TYPE_EDGE_FALLING>;
		spi-max-frequency = <10000000>;
		status = "disabled";
	};

	spidev0: spidev@0 {
		compatible = "toradex,evalspi";
		reg = <0>;
		spi-max-frequency = <23000000>;
		status = "okay";
	};
};

Thanks in advance.
Best regards,
Majd

Hi @majd.m

I noticed a delay between the bytes/words (about 4µs) while sending SPI frames as illustrated here.
I couldn’t figure out the reason of it. Is it not possible to send the bytes continuously without pausing the SCLK between the bytes? is this behaviour because of the SPI driver? if yes could you suggest a SPI transfer function/driver.

There were lot of changes for the SPI driver from 4.1 Kernel to 4.9 Kernel.

Could you update to the Bsp 2.8b6 and check if you have still the same delay between the transfers?

Best regards,
Jaski

Hello @jaski.tx

I updated it now to the Linux colibri-imx7-emmc 4.9.166-2.8.6.(with bsp 2.8b) the delay still unfortunately the same.
do you have suggestions? Thanks in advance.

Best regards,
Majd

Hi, are you aware that you set up the speed of the clock to 1MHz and not 10MHz.

oh god, I didn’t notice it even!. Thanks a lot, it looks much better now. (delay of ~360ns).

Perfect, that it is solved.
Best regards,
Jaski