cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in getting periodically reading of ADC1 multiple channels using TIM3 interrupt and DMA

Hugues Libotte
Associate III

On my STM32F030, I need to read analog values from three channels of the ADC1. These readings need to be periodical and I am using the TIM3 interrupt to trig the ADC value capture. When do not using DMA and collecting only one ADC channel value, everything works fine. As I need the three channels, I have to use DMA and once I activate this, I properly get a first value of the three channels but the ADC interrupt is never triggered any more and no new data are collected.

Any advice about this ?

Thanks

7 REPLIES 7
Javier1
Principal

>>TIM3 interrupt to trig the ADC value capture,

the interrupt doesnt need to be activated, just select the TIM update event .

But i dont think thats the cause of your problem

Similar question i had some time ago: https://community.st.com/s/question/0D53W00001AOJx3SAH/stm32f207-dmaadc-captures-only-one-channel-only-once

Video https://www.digikey.com/en/maker/projects/getting-started-with-stm32-working-with-adc-and-dma/f5009db3a3ed4370acaf545a3370c30c

we dont need to firmware by ourselves, lets talk

Thanks for answer but the problem onmy appears when DMA is used. In this case, even if TIM Update event is enable, I do not get periodic ADC capture. I only get once at startup of the uC

And if DMA is not used, everything works properly (on a single channel)

Thanks for the link to Digikey. Actually, I needed to enable DMA continuous request. Not sure this means that DMA values are updated at the TIM3 interrupt rate (I have to investigate power consumption). In the Digikey example they also enabled continuous conversion mode which is not wanted in my application.

Thanks for your support.

DMA continuous request: https://electronics.stackexchange.com/questions/500827/dma-continuous-request-functionality

>>this means that DMA values are updated at the TIM3 interrupt rate (I have to investigate power consumption).

I believe how this works is TIM triggers ADC triggers DMA, so effectively yes, DMa transfer will be triggered every TIM event

>>the Digikey example they also enabled continuous conversion mode which is not wanted in my application.

Thats fine, you got the basics there, if you choose normal conversion and you trigger them very frecuently ,have in mind, you could be starting a new conversion to soon and the last one didnt finished. DMa doesnt like this.

we dont need to firmware by ourselves, lets talk

In my case, this is every second so I assume there is no such issue :-)

As soon as I will inspect power consumption, I will keep you informed about the actual behaviour of who is trigerring who :-)

Thanks again

There is maybe one indication that he triggering of the ADC is maybe not only once due to TIM3 interrupt.

I have only three channels to convert.

In the code, I use HAL_ADC_Start_DMA(&hadc, value, 9) with 9 memory locations instead of 3 (which is the mandatory quantity)

In Debug mode, I stop at each TIM3 interrupt and I look at the "value" variable content and there are more than 3 elements which are updated. This means that the ADC makes more than one sequence of channel conversion... so from power consumption point of view, this would be not optimal. Evenmore as I do not know if the ADC and DMA are not running continuously...

OR maybe the amount in the HAL_ADC_Start_DMA call is driving the ADC behaviour and after 9 steps it stops ADC conversion...

Not clear for me.

Read out and check the TIM, ADC and DMA regiseters' content.

If you've clicked the code in CubeMX, it may be the "incorrect DMA initialization order in CubeMX" problem. Search in this forum.

JW