cancel
Showing results for 
Search instead for 
Did you mean: 

Read ADC Channel by Channel with hal

l90mehdi
Associate II
Posted on September 07, 2016 at 17:05

hello every one.

i want to run and use ADC on STM32f103.

i can read the analog value from ADC_1 and channel_0 in single mode.

but when i configure  ADC_1 and channel_0 ,channel_1 , channel_2 i can just read the 

analog value from channel_0.

how can i read ADC channel by channel which conflict does not occur?

//this is my main loop code.

int main(void)

{

  HAL_Init();

  SystemClock_Config();

  MX_GPIO_Init();

  MX_ADC1_Init();

  MX_CAN_Init();

  HAL_ADC_Start(&hadc1);

  while (1)

  {

    HAL_ADC_Start(&hadc1);

    if(HAL_ADC_GetValue(&hadc1) ==0)

{HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET);}

if(HAL_ADC_GetValue(&hadc1) !=0){HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,GPIO_PIN_RESET);HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET);}

  }

}

  
5 REPLIES 5
Posted on September 07, 2016 at 18:18

The method used by the STM32s for multiple channels is to enumerate a list, and have the ADC scan them and DMA the readings into an Array.

Polling them in a loop individually would require a lot of reconfiguration, so at least an order of magnitude more inefficient.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
l90mehdi
Associate II
Posted on September 07, 2016 at 19:12

Hi Dear clive1

yes.Polling mode in a loop individually would require a lot of reconfiguration and so it is very bad.

I will just test the ADC operation and i never use ADC in this mode.

so as i understand if  i want  to read ADC in two or more channels in all modes(scan mode-continuous mode,....), i should use DMA.is it true????

and if i want read ADC from two or more channels,can i use another method????

1 year ago i worked by LPC1788.

in this chip you can read ADC channel by channel without DMA.

ADC_ChannelGetData(LPC_ADC,0). zero in this function defines channel 0 

my question that is : how can i read ADC in multi channel without DMA???

is it possible????

thank you 

Posted on September 07, 2016 at 21:28

You have more than one ADC

I'm not saying it is impossible, but it is sufficiently impractical I'm not spending any of my time proving it one way or the other.

I'd opt to program it to take 3 samples at each start request, and throw away the two I didn't want right now.

The hardware is setup to do repetitive monitoring of signals autonomously, where all the processing is done in the DMA HT or TC interrupt when ALL the data is already available to act upon.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
l90mehdi
Associate II
Posted on September 07, 2016 at 21:49

thank you for your feedback clive1.

i am agree with you. best way is working with DMA.

 i am working on one simple project.in this project i can not use DMA.

so i am forced to use ADC without DMA.

if i want to use ADC without DMA, how can i read ADC in scan mode from 2 channels? 

thank you.

l90mehdi
Associate II
Posted on September 10, 2016 at 19:56

hi clive1.

i changed my code and now i want to use DMA  to transfer data because this way is better. 

how can i use DMA for transfer data in STM32F103????

thank you.