L031K6 : Please check my ADC-DMA code is correct !
I wish to get proper ADC value by ADC-DMA multi channels.
These ADC-DMA has 4 channels : trying to get 3 voltage data from 3 external port , and temperature data from one internal port.
but I realize I get quite incorrect value from external port ,
and also, temperature value is not trustable.
I guess my receiving ADC-DMA value methode which is using Interrupt is not proper..
So I will be very glad if you see my codes and check some possible errors.
for rough explaination, I tried to make these steps for getting ADC-DMA multi channel data
- ADC DMA Init
- Timer allows DMA interrupt regularly
- When DMA interrupt, adding adcBuffer
- interrupt act 50 times, stop DMA interrupt and averaging of these added adcBuffer
- read & use these averaged value
- phase 2 runs again
void DMA1_Channel1_IRQHandler(void)
{
HAL_DMA_IRQHandler(hadc.DMA_Handle);
// these "_total" value is unsigned long, these value will be averaged by " /MEASURE_RATE "
originalVolt_total+= adcBuffer[0];
referenceVolt_total += adcBuffer[1];
batteryVolt_total += adcBuffer[2];
measuringTimes+=1;
if(measuringTimes >= MEASURE_RATE ){ // If this Interrupt is occured 50 times then :
HAL_NVIC_DisableIRQ(DMA1_Channel1_IRQn); //disable to adding adc data
calculateADC(); // Averaging Phase
inMeasuring=0; // if Averaging Phase done, Tim2 reInit the DMA interrupt.
measuringTimes=1;
}
}
}
