cancel
Showing results for 
Search instead for 
Did you mean: 

How to read multiple channels of ADC without the DAM?

MDeva.1
Associate II

Hello,

I have 15ADC channel , I read the ADC channel when some external event is gnerated ,for eg when the battery is connected to one ADC channel then the interrupt gets generated then I have to read that channel , so in ADC interrupt handler I have to read all 15 pins then how I can know which pin channel of ADC is interrupt is generated , and in scan mode only enable or disble option is there so how I can know the ADC reading in forward or backward ,menas reading is from INP0 to INP1 or INP1 to INP0.

Here is code.

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)

{

uint8_t i=0;

if( __HAL_ADC_GET_FLAG(&hadc3,ADC_FLAG_EOC))

{

ADC3_Value[i++]=HAL_ADC_GetValue(&hadc3);

ADC3_flag[0]=1;

}

if(__HAL_ADC_GET_FLAG(&hadc3,ADC_FLAG_EOC))

{

ADC3_Value[i++]=HAL_ADC_GetValue(&hadc3);

ADC3_flag[1]=1;

}

if(__HAL_ADC_GET_FLAG(&hadc3,ADC_FLAG_EOC))

{

ADC3_Value[i++]=HAL_ADC_GetValue(&hadc3);

ADC3_flag[2]=1;

}

if(__HAL_ADC_GET_FLAG(&hadc3,ADC_FLAG_EOC))

{

ADC3_Value[i++]=HAL_ADC_GetValue(&hadc3);

ADC3_flag[3]=1;

}

if(__HAL_ADC_GET_FLAG(&hadc3,ADC_FLAG_EOC))

{

ADC3_Value[i++]=HAL_ADC_GetValue(&hadc3);

ADC3_flag[4]=1;

}

if(__HAL_ADC_GET_FLAG(&hadc3,ADC_FLAG_EOC))

{

ADC3_Value[i++]=HAL_ADC_GetValue(&hadc3);

ADC3_flag[5]=1;

}

if(__HAL_ADC_GET_FLAG(&hadc3,ADC_FLAG_EOS)) /*Flag for last conversion channel*/

{

ADC3_Value[i++]=HAL_ADC_GetValue(&hadc3);

ADC3_flag[6]=1;

i=0;

}

HAL_ADC_Start_IT(&hadc3);

}

6 REPLIES 6

Which STM32? Mistagged as STM32 MPU?

Why can't you use DMA?

Instead of spinning in blocking loops in a callback (interrupt context), why not simply light of a ADC/DMA request, and catch the data on the DMA completion?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Because the DMA are used for another peripherals so I dont have any DAM channel for ADC. and I have the 22 ADC which I have to use . And that ADC is connected to battery or another different ckt.I am working on STM32H745 series.

Perhaps you can use the Injected mode?

Or free up some resources so you can have DMA for capturing 22 channels of data. Not really in a position to judge if the other uses are critical, or the general balance of things.

But still, really don't want to be spinning in blocking loops within callbacks.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Ok thank you for your quick response.

Not sure how the cascading logic in there is supposed to work

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
TDK
Guru

There are 16+ DMA channels for use. You're using all of them for other things?

Configuring the ADC to read one channel and changing which channel that is between conversions is one way to approach this.

If you feel a post has answered your question, please click "Accept as Solution".