cancel
Showing results for 
Search instead for 
Did you mean: 

how to read multi channel ADC value

kalpeshpatil102
Associate III
Posted on December 18, 2016 at 08:27

hi,  i want read multiple ADC value .

for this i am using  

1)STM32f030f4p6tr core

2)STM32 cube mx 

3)keil u vision 5

 in my project i want read 3 different sensor value using ADC. for this project i used DMA  but DMA used interrupt because of dma use interrupt my other interrupt get conflict. so i want read adc value but didn't want to use interrupt .or  any other method to read multi channel adc value .

please help me.

i am new in stm32. 

thank you

6 REPLIES 6
Seb
ST Employee
Posted on December 18, 2016 at 09:45

If available, use ADC injected channels in cyclic sampling mode. See the STM32 ADC Checklist in community tips and tricks 

Posted on December 18, 2016 at 09:59

thenk you Seb Marsanne. i didn't know about ADC injected channel?

Posted on December 19, 2016 at 11:29

I am afraid that the ADC inside STM32F030 doesn't have injected channels. The regular ADC channels share one data register ADC_DR. If you don't want to use interrupts you have to poll the EOC flag in ADC interrupt and status register ADC_ISR and read the data after each conversion manually. With DMA you could just set the address in memory, enable the memory incrementation and then DMA would transfer conversion data to the memory automatically. What kind of problem are you facing? There is a possibility to set the preemption priority for each interrupt in the NVIC so that the interrupt with higher priority can interrupt the lower priority one.  

Posted on December 25, 2016 at 09:08

thank you Jaroslav ,

in my project i want read ADC value of two different sensor , for sensing first i used DMA but in when i read ADC data like HAL_ADC_Start_DMA(&hadc,uint32_t*)adc_buffer,2); when i add this in my code where i want to read adc value when it execute this instruction after  than i can read ADC value  it continuous read value but other function of code affected with DMA.

for checking this problem i wrote smll code like

while(1){

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, RESET);

HAL_ADC_Start_DMA(&hadc,uint32_t*)adc_buffer,2);

HAL_ADC_Stop(&hadc);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, SET);

}

according to code after reading of ADC Value GPIO_PIN_10 should toggle   but it didn't toggle . it only in SET . i think

due to DMA controller may can't process further function .

in my code i am using one timer interrupt . so i think DMA and timer get conflict.please help me

thank you. 

Posted on January 03, 2017 at 15:25

Patil

This is not correct.

The ADC peripheral is (except for very special cases) much slower then the CPU. In this case you configure the ADC and DMA, enable the conversion, but then you immediately stop the ADC conversion before it could be completed. 

There are a few interrupts generated by DMA controller - transfer complete, half-transfer complete and error.

The correct approach would be to start ADC together with DMA and before checking the conversion result (and stopping the ADC) wait for the transfer complete interrupt.

There is an example ADC_DMA_Transfer in STM32CubeF0 FW package. I would recommend you to go through it carefully to understand the principle.

You can download the package using CubeMX or using following link:

http://www.st.com/en/embedded-software/stm32cubef0.html

 

 The example is located here: STM32Cube_FW_F0_V1.7.0\Projects\STM32F030R8-Nucleo\Examples\ADC\ADC_DMA_Transfer

It can be easily modified.

What I would also recommend is to check return values of HAL functions. If everything is okay the functions return HAL_OK. 

It will help you to reveal problems very fast in the future.

In case there are still some issues, let me know.

Dhananjay Khairnar
Associate II
Posted on March 27, 2017 at 10:50

Please follow this tutorial.

https://youtu.be/ts5SEoTg2oY