0
\$\begingroup\$

I have a A/D where signals CPU(Analog Devices Blackfin 706) whenever it has new sample, and CPU reads that through a SPI, which is few bytes. Then waits for new smaple signal again.

My question is, can we use DMA here? Who and how should tell DMA to transfer new data? I can't tell DMA to watch for the signal itself, so somebody has to do it.

Does it make sense to use DMA? This is basically like an interrupt I/O. Everytime A/D signals new sample, main software tells DMA to transfer it. So there is no improvement in efficiency. main is still involved continuously in I/O.

\$\endgroup\$
2
  • \$\begingroup\$ For one sample every so often, no there is likely no point. But you haven't told us what hardware you are using - "DMA" is a very board term. \$\endgroup\$ Apr 4, 2017 at 22:31
  • \$\begingroup\$ I am using Analog Devices Blackfin706 DSP. \$\endgroup\$
    – doubleE
    Apr 4, 2017 at 22:44

2 Answers 2

2
\$\begingroup\$

The idea is you can use an interrupt to set up a transfer, then let the transfer run in the background. If you have more than 1 byte to transfer, using DMA would probably reduce the number of interrupts required. I presume that if the DMA and SPI modules are sufficiently powerful and interact correctly, you should be able to get away with 1 or 2 interrupts per sample (one to set up the transfer and possibly one more to deal with the sample after the transfer). Whether this is an advantage or not would depend on many things - what else the CPU is doing, the ADC sample rate, the SPI clock rate, etc.

\$\endgroup\$
3
  • \$\begingroup\$ I am a little lost on the DMA routine. So let's say every 1s an interrupt tells CPU that a sample is ready. Then CPU runs the SPI_ISR to read the sample. Where should we get DMA involved? Is it sufficient that DMA gets initialized only once in program with (src,dst,#bytes) and then it will run automatically whenever a sample is ready at its input? Then DMA will interrupt CPU whenever it has transferred the #bytes ? \$\endgroup\$
    – doubleE
    Apr 5, 2017 at 20:23
  • 1
    \$\begingroup\$ Depends on how the DMA module operates. For the DMA modules that I have used, it has to be set up and enabled to start the transfer. So in the sample ready ISR, you would set up the DMA transfer. The DMA module can usually be set up to trigger another ISR after the operation is finished, and in that ISR you can read the value out of wherever you set up the DMA module to write it to and do something with it. The idea is that you only need 2 interrupts for the whole transfer. Now, if your SPI clock is really slow and you only need to move a couple of bytes, maybe it's not worth it. \$\endgroup\$ Apr 6, 2017 at 0:25
  • 1
    \$\begingroup\$ @dandikain You are going to have to do your research now. The answer you seek is too complex for us to answer. I suggest you start here. \$\endgroup\$ Apr 6, 2017 at 0:26
2
\$\begingroup\$

It's what DMA is meant to do.

From Blackfin+ Core Embedded Processor

The baseline SPI peripheral is a synchronous, four-wire interface consisting of two data pins, one device select pin, and a gated clock pin. The two data pins allow full-duplex operation to other SPI-compatible devices. An additional two (optional) data pins are provided to support quad SPI operation. Enhanced modes of operation such as flow control, fast mode, and dual I/O mode (DIOM) are also supported. In addition, a direct memory access (DMA) mode allows for transferring several words with minimal CPU interaction.

Apparently yes.

The SPI port’s baud rate and clock phase/polarities are programmable, and it has integrated DMA channels for both transmit and receive data streams.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.