cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32 spi with triggered dma

Roberto Marino
Associate
Posted on November 16, 2017 at 16:54

Dear community,

my setup is build on top of stm32f439 and ADS131e4 ADC connected through spi.

The adc is set in continuous mode, so it fires an impulse on a pin (DRDY) as soon as a new sample is ready.

The sample consists of 15 bytes, and I would likee to read the packet using DMA in double buffer/circular mode.

I have tried many solutions without success.

My first solution was to simply trigger on the SPI4_RX request.

SPI4_RX/TX dma requests are on DMA2 Stream0/1 Channel 4.

Once programmed I don't need the tx dma channel, only the rx.

Some questions:

At this moment I don't want to take care about the double buffer switch so: do I need an interrupt handler for sure?

Furthermore, I don't want to transmit: do I need to setup the tx dma channel as well?

Final question: If i want to trigger the dma reading from spi can I use a timer channel request?

1 REPLY 1
S.Ma
Principal
Posted on November 16, 2017 at 21:22

Even if you don't want to use MOSI output, you still need to generate the SCK clock pulses... that their number depends on the TX DMA Buffer size. You can make it circular over a single byte with 15 bytes block transfer. Don't put interrupts on the TX DMA channel. Just rearm the counter to 15 when ready to launch a read sequence.

The DMA RX channel should go to a 15+ byte incoming buffer, prepared before the TX is launched. Get an interrupt when done to grab your 15 bytes. 

Or tune the SPI speed so that you scan 15 bytes continuously with a period slightly lower than the ADC conversion speed. In this case, use a continuous TX and 30+ bytes RX buffer. You can get interrupt at half empty and empty buffer in circular mode to save data without stopping the HW.