cancel
Showing results for 
Search instead for 
Did you mean: 

070RB hangs when reading a register

mike louaillier
Associate II
Posted on March 24, 2017 at 07:20

Hello can someone help me with this? it's a simple ADC conversion that hangs on line 8. i don't see how this is possible.

1      ADC1->CR |= (uint32_t)ADC_CR_ADSTART;  // start first conversion

2      count = 0;

3      while(((ADC1->ISR & ADC_ISR_EOC) == (uint32_t)reset)  &&  (count < timeout))  // wait for end of conversion

4        { count++; }

5      capVL = (uint16_t)ADC1->DR;  // read value

6      ADC1->CR |= (uint32_t)ADC_CR_ADSTART;  // start second conversion

7      count = 0;

8      while(((ADC1->ISR & ADC_ISR_EOC) == (uint32_t)reset)  &&  (count < timeout))  // wait for end of conversion

9        { count++; }

10//     while(count < timeout) count++;

11     capVH = (uint16_t)ADC1->DR;  // read value

if i conceal lines 8 & 9 and expose line 10, like so:

8//      while((ADC1->ISR & ADC_ISR_EOC) == (uint32_t)reset  &&  (count < timeout))  // wait for end of conversion

9//        { count++; }

10     while(count < timeout) count++;

then it runs fine. dunno why the ADC operation on line 6 isn't working, but working or not, it should still timeout and keep going. it's not supposed to just hang. WTF? it's just reading a register.

#register-access
11 REPLIES 11
Posted on July 04, 2017 at 08:32

Hello Mike and Jan,

as the reference manual for STM32F070RB (RM0360, rev 4) states, the ADC_ISR_EOC is cleared either by software writing 1 to it or by reading the ADC_DR register. I would be suspicious of debugger reading the ADC_DR register and thus clearing the flag. I don't know which version of the AC6 SW4STM32 do you have, but I have experienced this in the past with another IDEs. You could confirm this by reproducing the issue in debug session with the peripheral viewer for ADC opened and then trying to run the same code without debug. 

Posted on July 04, 2017 at 09:09

hmmm.... well now that's something i woulda never thought of. the buggy debugger interfering with program flow. but now i think about it, i wasn't using debug when the problem started happening. i ran the code numerous times before doing a debug session, and it was hanging every time.

but that was 3 months ago. the problem hasn't happened since but i'm living in fear that it will. knock on wood.

thanx for the reply :)