AnsweredAssumed Answered

Using DMA with communication peripherals

Question asked by grove.kevin on Jun 4, 2013
Latest reply on Jun 5, 2013 by grove.kevin
Hi all,

I just want to clear up my understanding of DMA and how it works with respect to communication peripherals such as SPI and I2C.

First, let's say I have a function that does some matrix multiplication and saves the result to some value 'multResult'.  Now I want to send that value over I2C to some other device in the network.  I can use DMA to tell the micro to move this value into the I2C2->DR reg to save a little CPU time, but in order to actually SEND the data over the bus, I need to initiate the 'start condition' from the main thread therefore causing the I2C communication to take up CPU time.  The DMA transfer cannot actually handle the communication itself, correct?

On the other hand, if I sent the data over an SPI bus as opposed to the I2C bus, the DMA controller could write 'multResult' to the SPI1 Tx register, therefore triggering an SPI transfer.  Am I correct in assuming that the SPI transfer taking place would still use CPU cycles in order to send the data across the bus?

Or  maybe I'm completely wrong, and I actually can use DMA to trigger and handle these transactions and save myself a LOT of CPU time.  If this is the case, please let me know!  That would mean that I just don't have my DMA configured quite right and I'll post some code.

Thanks in advance!


Edit:  I'm using a STM32L152RB micro by the way

Outcomes