Skip to main content
DU2
Associate II
October 5, 2020
Solved

L031K6 : Please check my ADC-DMA code is correct !

  • October 5, 2020
  • 7 replies
  • 1596 views

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

  1. ADC DMA Init
  2. Timer allows DMA interrupt regularly
  3. When DMA interrupt, adding adcBuffer
  4. interrupt act 50 times, stop DMA interrupt and averaging of these added adcBuffer
  5. read & use these averaged value
  6. 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;

     

   }  

 }

  

}

This topic has been closed for replies.
Best answer by Cwoo.1

​I saw your code.

If you want use DMA for record ADC, maybe use 'Interrupt Calibration Solution'.

7 replies

Uwe Bonnes
Chief
October 5, 2020

I wonder, if anybody is willing to scan through your code. A more sensible way is to start a simple example and then extend it step by step.

DU2
DU2Author
Associate II
October 5, 2020

ok I cut them off

Cwoo.1
Cwoo.1Best answer
Associate II
October 5, 2020

​I saw your code.

If you want use DMA for record ADC, maybe use 'Interrupt Calibration Solution'.

Cwoo.1
Associate II
October 5, 2020

Use 'HAL_ADC_Start_IT'

DU2
DU2Author
Associate II
October 6, 2020

thanks for help.

TDK
October 5, 2020

Could be your sample times are just not long enough. The temperature channel has a minimum sample time requirement, see datasheet.

"If you feel a post has answered your question, please click ""Accept as Solution""."
DU2
DU2Author
Associate II
October 6, 2020

It means trying to ' hadc.Init.SamplingTime ' longer makes temperature data more trustable ?​