SPI Write Speed Slow between iMX6 and DAC MCP4922

Dear @emmettbrown

The bottleneck is not the SPI communication, as you calculated correctly. The overhead comes from setting up the transfer.
The biggest contributors to this setup delay are:

  1. The .NET framework
    Managed code needs to be converted to executed assembly instructions, and switching between managed code (your application) and unmanaged code (the SPI lib) also quite some time.
  2. Handling the chip select
    Due to some limitation of the SPI peripheral controller, we need to implement the SPI-Chipselect signal through a regular GPIO which is toggled in the library code. This creates quite some overhead compared to a hardware-driven chip-select.

If you want to know the details, you should take an oscilloscope and do some measurements.

To achieve better performance, you can try the following approaches (sorted from easy-to-achieve to hard-to-implment):

  1. If your application and DAC allows it, do a large transfer which contains multiple samples. E.g. if the ADC accepts continues data reception (2 bytes per sample), just send 2000 bytes at once to get an output of 1000 samples.
  2. Write the code to output a series of samples in native C. Do only one call from C# to your native-C function to output a series of samples.
  3. Purchase the SPI Library source code and optimize it for your particular use case.

Regards, Andy