How can I reduce the spi access delay?

Hello,

The spi access delay is jagged, and sometimes it is measured as 50us or more, 70us or more or more as follows.

The target time is less than 35us.
To satisfy 16-byte spi access more than 20,000 times per second, delay must be stably less than 35us.

image

The spi transfer function and how to use it are as follows.

int SpiAccTransferDev(pJETSON_SPI_CTRL pSpiCtrl, int size, unsigned char* tx_buf, unsigned char* rx_buf)
{
	int ret;
	struct spi_ioc_transfer tr;
	int ntransfers = 1;

//	fprintf(stderr,"vvvv%s(%d)[0x%02x,%d]\n", __FUNCTION__, __LINE__, *tx_buf, size);

	memset(&tr, 0, sizeof(struct spi_ioc_transfer));

	tr.tx_buf = (unsigned long)tx_buf;
	tr.rx_buf = (unsigned long)rx_buf;
	tr.len = size;		// The size mean byte count for tx_buf and rx_buf
	tr.delay_usecs 		= pSpiCtrl->spi_delay;
	tr.speed_hz 		= pSpiCtrl->spi_speed;
	tr.bits_per_word	= pSpiCtrl->spi_bits;
	tr.cs_change = 1;
	tr.pad = 0;

	ret = ioctl(pSpiCtrl->spi_device, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 0){
		fprintf(stderr, "Error : It can't send spi message with (%s)\n", JETSON_SPI_DEVICE_PATH);
		return -1;
	}
	return ret;
}


gSpiLoopRun = 1;
while(gSpiLoopRun) 
{

        //Read================================================================================
        tx_buf[0] = 0x00;	// Read FIFO 8 Channel
        txrx_size = MAX11636_BUFF_MAX;
        SpiAccTransferDev( pSpiCtrl, txrx_size, tx_buf, rx_buf);

}

Thank you.

Hello,

Channel 2 is GPIO.
As in the attached source code, after lowering the GPIO to LOW and executing the SpiAccTransferDev function, the process of raising the GPIO to HIGH is repeated.
No. 2 (green) delay is longer than No. 1 (red).
Is there any way to improve this?

gSpiLoopRun = 1;
while(gSpiLoopRun) 
{

        //Read================================================================================
        tx_buf[0] = 0x00;	// Read FIFO 8 Channel
        txrx_size = MAX11636_BUFF_MAX;
        GpioAccSetValue(g_conversion_gpio_id, GPIO_LOW);
        SpiAccTransferDev( pSpiCtrl, txrx_size, tx_buf, rx_buf);
        GpioAccSetValue(g_conversion_gpio_id, GPIO_HIGH);

}

Thank you.

Hello, @ShaneCCC

Is there any progress?

Thank you.

Hello, @ShaneCCC

When the same code is run on Raspberry Pi, it is faster than on Jetson as follows. May I please confirm?

Thank you.

Could you share the device tree to check.
You can dump the dtb by below command and attached the spi.dts here.

sudo dtc -I fs -O dts -o spi.dts /proc/device-tree
1 Like

There is no update from you for a period, assuming this is not an issue any more.
Hence we are closing this topic. If need further support, please open a new one.
Thanks

Is this still an issue to support? Any result can be shared? Thanks

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.