It might be a bit out there, but for a project that I am working on, my word size default is 24bits (3x8-bit), of which the first 8-bits are data and the next 16-bits are data. I would like to transfer it out of the system as fast as possible with minimal calls to the sub-routines. For this I am trying to reduce the number of calls, I have managed to reduce it from 3 to 2, Can I possibly make it 1 call.
My first attempt was to use 3x SPI.transfer() Second was to use 1x
SPI.transfer() and 1x SPI.transfer16()
I would like to know what would be the ideal way to write a SPI.transfer24 function.
-
What teensy are you using?Majenko– Majenko12/23/2020 19:40:25Commented Dec 23, 2020 at 19:40
-
teensy 4.0 is the one i am usingsandeepzgk– sandeepzgk12/23/2020 20:03:07Commented Dec 23, 2020 at 20:03
-
And how much difference do you think making 1 function call as opposed to 2 will make at 600MHz? Will you even be able to tell?Majenko– Majenko12/23/2020 20:04:00Commented Dec 23, 2020 at 20:04
-
1@Majenko that is a fair point, but if you try to look at a digital logic level analyzer each word seems to to have a small impact, but when you write ~4M words a second it adds up unfortunately.sandeepzgk– sandeepzgk12/23/2020 20:19:17Commented Dec 23, 2020 at 20:19
1 Answer 1
You can't. The teensy 4.0 has hardware support for 8-bit, 16-bit and 32-bit transfers. Not 24-bit transfers.
But at 600MHz the overhead of making a function call is negligible anyway - certainly compared to the speed of SPI which is at best about 30x slower than the CPU operates at.
If you want high throughput you won't be wanting to use the SPI library anyway, instead you'd be using DMA to transfer your data with minimal CPU intervention.