2022-04-08 09:45 AM
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);
}
2022-04-08 10:07 AM
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?
2022-04-08 10:10 AM
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.
2022-04-08 10:22 AM
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.
2022-04-08 10:25 AM
Ok thank you for your quick response.
2022-04-08 10:40 AM
Not sure how the cascading logic in there is supposed to work
2022-04-08 11:10 AM
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.