Stm32f4: DMA + ADC Transfer pausing

半世苍凉 提交于 2019-12-12 02:43:00

问题


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:

  1. Initialize DMA and ADCs
  2. Wait for an external interrupt
  3. Pause the DMA transfer
  4. Send the buffered data through USART
  5. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!