Wrong SPI-frequency using spidev_test

Hello Guys,

I’m new at programming the BBB and to Linux in general, so I’m trying to figure out what’s happening when I’m setting up a SPI-connection.

I have set up a SPI-connection, using a Device Tree Overlay, and I’m now running spidev_test.c to test the connection. For the application I’m making, I need a quite specific frequency. So when I run spidev_test and measure the frequency of the bits shiftet out, I don’t get the expected frequency.

I’m sending a SPI-packet containing 0xAA, and in spidev_test I’ve modified the “spi_ioc_transfer.speed_hz” to 4000000 (4MHz). But I’m measuring a data transfer frequency of 2,98MHz. I’m seeing the same result with other speeds as well, deviations are usually around 25-33%.

How come the measured speed doesn’t match the assigned speed?

How is the speed assigned in “speed_hz” defined?

How precise should I expect the frequency to be?

Thank you :slight_smile:

Because you are not “assigning” a speed. You are setting a “maximum” speed, and the system is free to generate any standard available frequency slower than the maximum.

Because of the clock divider chains feeding the SPI, it is not possible to generate any arbitrary speed. You may be able to get closer to what you want by bit banging the registers inside of the Sitara. If you are able to hit some specific speed, consider yourself very lucky. Time to get out the Sitara data sheet and start reading.

— Graham