2022-07-06 04:15 AM
2022-07-06 06:12 AM
It depends... on which CPU, which clock speed, what else is going on (other interrupts/DMA), and on what you mean by "more efficient". There are trade-offs in each method.
Toggle a pin before starting and again after it is done, put that pin and the SPI MOSI signal on a scope and see what happens. Or use a timer to time how long it takes. See which works best in your application. If the timing doesn't make sense, post your results here.
2022-07-06 07:07 AM
As said @Bob S it depends.
As an example imagine a low power system with a clock of 16 MHz, and you want to use a SPI at 8 MHz.
If you use interrupts, you will observe silence between bytes on the SPI line if you plug a scope. Because the transmission is fast compared to system clock, interrupt handling and byte transmission have a timing of the same magnitude, so the MCU load is high, and the transmission time not optimal.
If you use DMA the data bytes can be contiguous on the data line, therefore the data buffer is transmitted in a shorter time. Also during the transmission the CPU can do something else. In this sense we can say that the use of DMA is more efficient.
But... If you only have a few bytes to transmit, the time it takes to set up the DMA can be more than the gain when transmitting, especially when the SPI has a FIFO.
You also have to consider how the code is written. The HAL is very generic so absolutely not optimized.
So there is no easy answer. You really have to analyze case by case.