问题
On the Stm32f4-Discovery board I've configured the tripple ADC Interleaved mode with DMA writing the ADC data in circular mode 2. Everything works fine, but I can't pause the transfer properly to transfer the data in the buffer through USART (the transform is performed inside an external interrupt vertor function). I am trying to implement such an algorithm:
- Initialize DMA and ADCs
- Wait for an external interrupt
- Pause the DMA transfer
- Send the buffered data through USART
- Resume the DMA transfer, goto step 2
One thing I tried was
DMA_Cmd(DMA2_Stream0, DISABLE);
ADC_Cmd(ADC1, DISABLE); ADC_Cmd(ADC2, DISABLE); ADC_Cmd(ADC3, DISABLE);
... Send the buffered data over USART ...
ADC_Cmd(ADC1, ENABLE); ADC_Cmd(ADC2, ENABLE); ADC_Cmd(ADC3, ENABLE);
DMA_Cmd(DMA2_Stream0, ENABLE);
That's fine, but at some point the DMA just becomes stuck at the first bit and does not "move" through all the buffer array. I've also tried just stopping the RCC Clocks for the ADCs
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, DISABLE); //So on for ADC2 and ADC3
But it does the same, the only difference is that the first method stops the DMA transfer at some point (therefore, sometimes it pauses the DMA normally), and the second method stops the DMA never works okay.
I also read in the reference manual that
If the conversion sequence is interrupted (for instance when DMA end of transfer occurs), the multi-ADC sequencer must be reset by configuring it in independent mode first (bits DUAL[4:0] = 00000) before reprogramming the interleaved mode.
I've tried setting the ADC to the independent mode when pausing and then setting the ADC to the tripple interleaved mode in both methods described above, but that did not change the situation a bit.
So, the question is - what is the right way to pause the DMA transfer, so that the buffered data that I am trying to send over USART does not change?
来源:https://stackoverflow.com/questions/39453183/stm32f4-dma-adc-transfer-pausing