2021-01-04 08:24 AM
Hello,
I am using the STM32F303K8 on the Nucleo-F303K8 to measure multiple ADC channels and update a control loop based on the values. I have set up ADC1 using the DMA in circular mode to read channels IN1, IN2, and IN4. I have a buffer set up in which I place the values of the ADC. I also have a timer running so that upon the timer interrupt, the DMA will stop, I read the values of the buffer into designated arrays (one for each channel), then restart the DMA and the timer. ADC1 is set up so that IN1, IN2, and IN4 have rank 1, rank2, and rank3 respectively. The problem I am facing is that each time I restart the DMA, it changes the index of the DMA buffer for each ADC channel. So for example, during testing, I have IN1 connected to 3.3V, IN2 connected to 0V and IN4 connected to 1.65V.
The first time I stop the DMA and read the buffer I see these values.
This makes sense because the first channel should be highest, second channel should be around 0, and third channel should be about half the first channel. However, after running my code and stop/start the DMA multiple times, I can see that the buffer shows the following:
Now, the IN2 value seems to be in the [0] index spot of the buffer, IN4 in the [1] index spot, and IN1 in the [2] index spot.
How do I specify the index of each ADC channel in the DMA buffer so that it is consistent each time? Or at least how can I keep it from changing? I would like to be able to stop the DMA, read each channel from the buffer into its own array for each ADC1 channel, then restart the buffer until next time.
Thank you,
Sean
2021-01-04 09:12 AM
Why are you using circular mode if you're just stopping and restarting it at every timer interrupt?
One solution would be to let it keep running. This is what I would do.
Another solution would be to use non-circular mode.
Another solution would be to reinitialize the ADC and DMA each time. This may require DeInit and/or force resetting of the peripheral.