Jetson TX2 SPI Clock Frequency


I am communicating my Jetson TX2 to a DRV8305 driver board via SPI.

In order to do that, I am using “ioctl”. The thing is that even if I set the value of SPI_IOC_WR_MAX_SPEED_HZ to 400.000 (400kHz), when I measure it I just get a 10 times slower Clock Frequency.

        uint32_t mode1 = SPI_MODE_1;
        uint8_t bits = 16; 
        uint32_t speed = 400000;

        int fd = open("/dev/spidev3.0", O_RDWR);
        ioctl(fd, SPI_IOC_WR_MODE, &mode1);
        ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
        ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);

So, I tried rising it to 4.000.000 Hz (4MHz) and, following the previous attempt, it provided 400kHz, again, 10 times slower. (Measured using an osciloscope).

I can’t find a reason on why this happens. Does anyone have an answer to this?

Thank you for your help.

Have a check with read it back like

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");

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

Thanks for your response Shane.

I checked as you mentioned and this is what I got:

    spi mode: 0x1
    bits per word: 16
    max speed: 4000000 Hz (4000 KHz)

As I mentioned, 4000000 Hz are being written but I measure a ten times slower frequency.

Could you try the spidev-test -s xxxxx to check if can set to correct speed.
Also what the spi-max-frequency in the device tree?

I was not able to check that.

However, I got to solve the issue. There was a prescaler on the script I was using.

Thanks a lot for the help, tho.