cancel
Showing results for 
Search instead for 
Did you mean: 

ADC EOC wont go down after reading DR

marcadell
Visitor

Hi,
I already tried to search for previous threads that could help me (like this one), sadly without success.
I'm currently studying the ADC peripheral on STM32F3DISCOVERY from the reference manual. I started writing a simple program to measure a tension on PA0. It all works flawlessly until the ADC samples the value on PA0, stores it in the Data Register and raises EOC. From the manual:
"The ADC sets the EOC flag as soon as a new regular conversion data is available in the
ADCx_DR register. An interrupt can be generated if bit EOCIE is set. EOC flag is cleared by
the software either by writing 1 to it or by reading ADCx_DR." (page 347, Section 15.3.23).
The loop part of my code is the following (I already configured the ADC for single conversion mode, L[3:0] = 0000, DIFSEL=0 and so on... to rule out any problem with configuration):

unsigned int ADC_value = 0;

while(1){

 ADC1->CR |= ADSTART;

//wait for EOC=1

while((ADC1->ISR&EOC) != EOC);

//Data register read

ADC_value = (ADC1->DR);

//custom wait function in ms

wait_ms(1000);

};//end while

};//end main

Executing the program in debug mode clearly shows that DR is updated and EOC is raised.

A possible (dumb, I acknowledge it) workaround that I came up with was setting EOC=0 by S/W, but the program refuses to proceed after the while, no matter what's written next:

unsigned int ADC_value = 0;

while(1){

 ADC1->CR |= ADSTART;

//wait for EOC=1

while((ADC1->ISR&EOC) != EOC);

 ADC1->ISR &= ~EOC;

 ADC1->CR|=ADSTART;

//Data register read

ADC_value = (ADC1->DR);

//custom wait function in ms

wait_ms(1000);

};//end while

};//end main

 

0 REPLIES 0