Data transfer time using SPI communication on Jetson Xavier agx does not change with change in bits per word and speed

Hello,
I am working on development of SPI communication on Jetson xavier agx. I’ve referred the spidev_test code and modified my code for spi communication. I have written a kernel of matrix vector multiplication and want to send the data over spi. For now, I am doing loopback test. I am able to send and receive data using 32 bits per word. However,If I change the bits per word from 32 to 8, the time required for SPI transfer should increase, right? Also, with the change in speed, the data transfer time should vary. But, whatever value I keep for bits per word and speed, I am getting the same timing for data transfer over SPI.

Following are the snippets of my code:

static const char *device = "/dev/spidev0.1";
static uint32_t mode;
static uint8_t bits = 32;
static uint32_t speed = 4000000;
static uint16_t delay;

static void printResponse(double const buffer[], int size)
{
for (int i = 0; i < size; i++) {
	printf("%f ", buffer[i]);
}
puts("");
}

 static void transfer(int fd, double const *tx, double const *rx, size_t len)
{

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

int ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);

if (ret == 1)
	pabort("!!! ERROR !!! \n");
else
	printf("Message sent successfully \n");

printf("Printing the response \n");

printf("TX : \t");
printResponse(tx, 262);
printf("RX : \t");
printResponse(rx, 262);
printf("************************************************************************* \n");
   }



for (int samples = -1; samples < 100000; samples++)
{
	struct timespec before;
	clock_gettime(CLOCK_REALTIME, &before);

	const int threadsPerBlock = 32;
	const int blocksPerGrid = rowBD;

	csr_spmv_vector_kernel<double>
		<< < blocksPerGrid, threadsPerBlock >> > (rowBD, d_col_ids, d_row_ptr, d_data, d_x, d_BD, d_u, d_y);

	
	cudaMemcpy(d_x, d_y, sizeRowBD, cudaMemcpyDeviceToDevice);

	transfer(fd, d_u, d_y, sizeof(h_y));

	struct timespec after;
	clock_gettime(CLOCK_REALTIME, &after);

	timings.append(before, after);
}

 int main()
{

int ret = 0, fd;

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 spi bits per word");

ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
	if (ret == -1)
		pabort("Can't get spi 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");

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

printf("spi mode: 0x%x \n", mode);
printf("bits per word: %d\n", bits);
printf("max speed: %d Hz (%d MHz) \n", speed, speed / 1000000);

Could you please help me with this issue?

Thanks in advance…!!

Why do you think the data but per 32 and 8 bits consume different times?
Any concern for this behavior?

Hi @ShaneCCC , sorry for my late reply. Sorry, actually i misunderstood the concept of spi transfer. Initially I thought that bits per word which we set (8 or 32) are transferred during one clock cycle. However, one bit of data is transferred in each clock cycle, so the speed of data transfer is determined by the frequency of the clock signal, not by bits per word. I tried with changing the speed in above code, but still I’m getting the same timing for spi transfer. Could you please help me with this?

Do you mean “the same timing for spi transfer” from the scope or from the time diff of kernel driver?

From the time difference of kernel driver.

I don’t think that profiling meaningful due to it could be relative with system interrupt timing and system scheduling.

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