The documentation on the SPI peripheral says:

Two DMA channels are required, one to read from and one to write to the SPI.

Is this necessarily true? I have a device where I need to write a few bytes by SPI and then receive a very large amount of data (eg 32k) back over SPI.

Is it possible to do the write portion (ie sending a few bytes to the slave) by directly accessing the SPI peripheral, then setting up DMA to receive the response back? Or do I need to set up two DMA transfers, one of which writes a few significant bytes and then a big pile of junk, and the other receives a few bytes of junk and then 32k of interesting data?

  • Surely you need to keep the write buffer filled? If it empties the SPI transfer will stall.
    – joan
    Aug 14 '18 at 16:37
  • Possibly this is my ignorance of SPI or the SPI peripheral - is it necessary to continuously send and receive on the SPI bus? The device I'm talking to is an MCP3914 analog front end, which has a continuous-read mode, where you request the first register you want to read and then keep CS active and it cycles through reading all its registers; I want to do this more or less indefinitely and so don't really want to tie up a second DMA channel writing I-don't-care-what (actually an infinite chain of 0s) to the device.
    – Tom
    Aug 15 '18 at 9:44
  • Looking further, it looks like I can do the write portion of the transaction by accessing the SPI peripheral directly, then do the read portion using DMA, with the outgoing DMA channel set up to read from a single word in memory with the SRC_INC field set to 0 so that it always reads from the same location. I think.
    – Tom
    Aug 15 '18 at 10:13

The problem you face is that - assuming you're the master - in order to receive the 32k of interesting data you need to generate SCLK for all of it. And the way you generate SCLK is by writing transmit data, even if it's a big pile of junk.

So unless you can figure out a way for the receive DMA channel to also write dummy transmit data, you're kind of stuck with having to use two channels.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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