SPI Timing on the Pi

So I've just tidied up my old SPI timing program on the Pi and here are the
results on the latest kernel.
I cycled the SPI clock rate from 1 to 32Mhz and exchanged a buffer from 1
to as many as I could before the hardware timed out (an artificial timeout
in the kernel driver fixed at 150mS)
The 2nd last column is the effective transfer speed however the
transactions per second (TpS) column is probably more interesting -
so e.g. sampling a 12-bit ADC which needs a 16-bit (2 byte) transaction
with the SPI speed at 2Mhz has a limitation of 16K samples/sec...
(each row is averaged over 100 tests)
Source code at
formatting link
but it'll be in
the next release of wiringPi.
(I'm wondering if I've calculated the latency correctly now...)
Enjoy,
Gordon
+-------+--------+----------+----------+-----------+------------+
| MHz | Size | mS/Trans | TpS | Mb/Sec | Latency mS |
+-------+--------+----------+----------+-----------+------------+
| 1 | 1 | 0.060 | 16666.7 | 0.12716 | 0.05200 |
| 1 | 2 | 0.090 | 11111.1 | 0.16954 | 0.07400 |
| 1 | 4 | 0.100 | 10000.0 | 0.30518 | 0.06800 |
| 1 | 8 | 0.150 | 6666.7 | 0.40690 | 0.08600 |
| 1 | 16 | 0.230 | 4347.8 | 0.53074 | 0.10200 |
| 1 | 32 | 0.370 | 2702.7 | 0.65984 | 0.11400 |
| 1 | 64 | 0.680 | 1470.6 | 0.71806 | 0.16800 |
| 1 | 128 | 1.280 | 781.2 | 0.76294 | 0.25600 |
| 1 | 256 | 2.460 | 406.5 | 0.79395 | 0.41200 |
| 1 | 512 | 4.820 | 207.5 | 0.81043 | 0.72400 |
| 1 | 1024 | 9.530 | 104.9 | 0.81978 | 1.33800 |
| 1 | 2048 | 18.990 | 52.7 | 0.82280 | 2.60600 |
| 1 | 4096 | 37.900 | 26.4 | 0.82454 | 5.13200 |
| 1 | 8192 | 75.690 | 13.2 | 0.82574 | 10.15400 |
| 1 | 16384 SPI failure: Connection timed out
+-------+--------+----------+----------+-----------+------------+
+-------+--------+----------+----------+-----------+------------+
| MHz | Size | mS/Trans | TpS | Mb/Sec | Latency mS |
+-------+--------+----------+----------+-----------+------------+
| 2 | 1 | 0.080 | 12500.0 | 0.09537 | 0.07600 |
| 2 | 2 | 0.070 | 14285.7 | 0.21798 | 0.06200 |
| 2 | 4 | 0.090 | 11111.1 | 0.33908 | 0.07400 |
| 2 | 8 | 0.100 | 10000.0 | 0.61035 | 0.06800 |
| 2 | 16 | 0.150 | 6666.7 | 0.81380 | 0.08600 |
| 2 | 32 | 0.240 | 4166.7 | 1.01725 | 0.11200 |
| 2 | 64 | 0.390 | 2564.1 | 1.25200 | 0.13400 |
| 2 | 128 | 0.670 | 1492.5 | 1.45756 | 0.15800 |
| 2 | 256 | 1.270 | 787.4 | 1.53789 | 0.24600 |
| 2 | 512 | 2.450 | 408.2 | 1.59439 | 0.40200 |
| 2 | 1024 | 4.820 | 207.5 | 1.62085 | 0.72400 |
| 2 | 2048 | 9.550 | 104.7 | 1.63613 | 1.35800 |
| 2 | 4096 | 19.010 | 52.6 | 1.64387 | 2.62600 |
| 2 | 8192 | 37.920 | 26.4 | 1.64821 | 5.15200 |
| 2 | 16384 | 75.740 | 13.2 | 1.65038 | 10.20400 |
| 2 | 32768 SPI failure: Connection timed out
+-------+--------+----------+----------+-----------+------------+
+-------+--------+----------+----------+-----------+------------+
| MHz | Size | mS/Trans | TpS | Mb/Sec | Latency mS |
+-------+--------+----------+----------+-----------+------------+
| 4 | 1 | 0.050 | 20000.0 | 0.15259 | 0.04800 |
| 4 | 2 | 0.060 | 16666.7 | 0.25431 | 0.05600 |
| 4 | 4 | 0.060 | 16666.7 | 0.50863 | 0.05200 |
| 4 | 8 | 0.070 | 14285.7 | 0.87193 | 0.05400 |
| 4 | 16 | 0.090 | 11111.1 | 1.35634 | 0.05800 |
| 4 | 32 | 0.140 | 7142.9 | 1.74386 | 0.07600 |
| 4 | 64 | 0.240 | 4166.7 | 2.03451 | 0.11200 |
| 4 | 128 | 0.390 | 2564.1 | 2.50401 | 0.13400 |
| 4 | 256 | 0.700 | 1428.6 | 2.79018 | 0.18800 |
| 4 | 512 | 1.290 | 775.2 | 3.02810 | 0.26600 |
| 4 | 1024 | 2.470 | 404.9 | 3.16296 | 0.42200 |
| 4 | 2048 | 4.840 | 206.6 | 3.22831 | 0.74400 |
| 4 | 4096 | 9.550 | 104.7 | 3.27225 | 1.35800 |
| 4 | 8192 | 19.040 | 52.5 | 3.28256 | 2.65600 |
| 4 | 16384 | 37.980 | 26.3 | 3.29121 | 5.21200 |
| 4 | 32768 | 75.860 | 13.2 | 3.29554 | 10.32400 |
| 4 | 65536 SPI failure: Connection timed out
+-------+--------+----------+----------+-----------+------------+
+-------+--------+----------+----------+-----------+------------+
| MHz | Size | mS/Trans | TpS | Mb/Sec | Latency mS |
+-------+--------+----------+----------+-----------+------------+
| 8 | 1 | 0.140 | 7142.9 | 0.05450 | 0.13900 |
| 8 | 2 | 0.040 | 25000.0 | 0.38147 | 0.03800 |
| 8 | 4 | 0.050 | 20000.0 | 0.61035 | 0.04600 |
| 8 | 8 | 0.060 | 16666.7 | 1.01725 | 0.05200 |
| 8 | 16 | 0.070 | 14285.7 | 1.74386 | 0.05400 |
| 8 | 32 | 0.120 | 8333.3 | 2.03451 | 0.08800 |
| 8 | 64 | 0.150 | 6666.7 | 3.25521 | 0.08600 |
| 8 | 128 | 0.230 | 4347.8 | 4.24592 | 0.10200 |
| 8 | 256 | 0.380 | 2631.6 | 5.13980 | 0.12400 |
| 8 | 512 | 0.690 | 1449.3 | 5.66123 | 0.17800 |
| 8 | 1024 | 1.280 | 781.2 | 6.10352 | 0.25600 |
| 8 | 2048 | 2.470 | 404.9 | 6.32591 | 0.42200 |
| 8 | 4096 | 4.840 | 206.6 | 6.45661 | 0.74400 |
| 8 | 8192 | 9.620 | 104.0 | 6.49688 | 1.42800 |
| 8 | 16384 | 19.100 | 52.4 | 6.54450 | 2.71600 |
| 8 | 32768 | 38.120 | 26.2 | 6.55824 | 5.35200 |
| 8 | 65536 | 76.210 | 13.1 | 6.56082 | 10.67400 |
| 8 | 131072 SPI failure: Connection timed out
+-------+--------+----------+----------+-----------+------------+
+-------+--------+----------+----------+-----------+------------+
| MHz | Size | mS/Trans | TpS | Mb/Sec | Latency mS |
+-------+--------+----------+----------+-----------+------------+
| 16 | 1 | 0.060 | 16666.7 | 0.12716 | 0.05950 |
| 16 | 2 | 0.060 | 16666.7 | 0.25431 | 0.05900 |
| 16 | 4 | 0.060 | 16666.7 | 0.50863 | 0.05800 |
| 16 | 8 | 0.060 | 16666.7 | 1.01725 | 0.05600 |
| 16 | 16 | 0.070 | 14285.7 | 1.74386 | 0.06200 |
| 16 | 32 | 0.090 | 11111.1 | 2.71267 | 0.07400 |
| 16 | 64 | 0.150 | 6666.7 | 3.25521 | 0.11800 |
| 16 | 128 | 0.190 | 5263.2 | 5.13980 | 0.12600 |
| 16 | 256 | 0.270 | 3703.7 | 7.23380 | 0.14200 |
| 16 | 512 | 0.410 | 2439.0 | 9.52744 | 0.15400 |
| 16 | 1024 | 0.730 | 1369.9 | 10.70205 | 0.21800 |
| 16 | 2048 | 1.310 | 763.4 | 11.92748 | 0.28600 |
| 16 | 4096 | 2.510 | 398.4 | 12.45020 | 0.46200 |
| 16 | 8192 | 4.890 | 204.5 | 12.78119 | 0.79400 |
| 16 | 16384 | 9.680 | 103.3 | 12.91322 | 1.48800 |
| 16 | 32768 | 19.310 | 51.8 | 12.94666 | 2.92600 |
| 16 | 65536 | 38.570 | 25.9 | 12.96344 | 5.80200 |
| 16 | 131072 | 77.190 | 13.0 | 12.95505 | 11.65400 |
| 16 | 262144 SPI failure: Connection timed out
+-------+--------+----------+----------+-----------+------------+
+-------+--------+----------+----------+-----------+------------+
| MHz | Size | mS/Trans | TpS | Mb/Sec | Latency mS |
+-------+--------+----------+----------+-----------+------------+
| 32 | 1 | 0.050 | 20000.0 | 0.15259 | 0.04975 |
| 32 | 2 | 0.050 | 20000.0 | 0.30518 | 0.04950 |
| 32 | 4 | 0.060 | 16666.7 | 0.50863 | 0.05900 |
| 32 | 8 | 0.060 | 16666.7 | 1.01725 | 0.05800 |
| 32 | 16 | 0.040 | 25000.0 | 3.05176 | 0.03600 |
| 32 | 32 | 0.060 | 16666.7 | 4.06901 | 0.05200 |
| 32 | 64 | 0.100 | 10000.0 | 4.88281 | 0.08400 |
| 32 | 128 | 0.130 | 7692.3 | 7.51202 | 0.09800 |
| 32 | 256 | 0.170 | 5882.4 | 11.48897 | 0.10600 |
| 32 | 512 | 0.270 | 3703.7 | 14.46759 | 0.14200 |
| 32 | 1024 | 0.470 | 2127.7 | 16.62234 | 0.21400 |
| 32 | 2048 | 0.830 | 1204.8 | 18.82530 | 0.31800 |
| 32 | 4096 | 1.520 | 657.9 | 20.55921 | 0.49600 |
| 32 | 8192 | 2.840 | 352.1 | 22.00704 | 0.79200 |
| 32 | 16384 | 5.120 | 195.3 | 24.41406 | 1.02400 |
| 32 | 32768 | 10.650 | 93.9 | 23.47418 | 2.45800 |
| 32 | 65536 | 20.880 | 47.9 | 23.94636 | 4.49600 |
| 32 | 131072 | 40.990 | 24.4 | 24.39619 | 8.22200 |
| 32 | 262144 | 82.730 | 12.1 | 24.17503 | 17.19400 |
| 32 | 524288 | 167.140 | 6.0 | 23.93203 | 36.06800 |
| 32 | 1048576 SPI failure: Connection timed out
+-------+--------+----------+----------+-----------+------------+
Reply to
Gordon Henderson
Loading thread data ...
How did you calculate latency? Latency is one of those terms that gets tossed around a lot without much appreciation of what it really means. It is supposed to mean the time delay for the first data sample to be returned after the process is started. It has no relation to the transfer speed.
--

Rick
Reply to
rickman

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.