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 March 24, 2017 at 08:45

Is the count variable qualified as volatile?

How do you know the program hangs on line 8? What is the content of ADC registers when it hangs?

JW

Posted on March 25, 2017 at 01:07

ok i made it a volatile but it didn't seem to make a difference.

and maybe it's not line 8. but i do what i always do, disable lines 8 & 9 and run it again. if the code runs correctly the second time, then i figure line 8 is the culprit. i repeat the test once or twice more, run it with and without lines 8 & 9.

here's the register values:

0690X00000606dEQAQ.png

thanx

S.Ma
Principal
Posted on March 25, 2017 at 15:37

Which device is used?

Posted on March 25, 2017 at 18:57

it's a nucleo board with a stm32f070rb mcu

Posted on March 25, 2017 at 19:18

Just to make sure, try by replacing 'reset' by 0

Posted on March 25, 2017 at 19:56

well yeah it couldn't hurt but now the IDE is not connecting to the board so if it ain't one thing it's another...

Posted on March 26, 2017 at 04:22

well ok after 6 hours i got a new IDE and no it's still freezing at line 8

Posted on March 26, 2017 at 08:43

Post a minimal but complete compilable example exhibiting the problem.

JW

Posted on March 27, 2017 at 01:44

well it looks as though the problem spontaneously resolved. i Xed out the usb function and ran the program again. the problem went away. the program stopped hanging at the ADC routine. the usb, it seems, was interfering.

but then i re-included the usb function and now the ADC still works fine. since the problem won't happen now, i can never figure out what it was.

so the problem is resolved but never solved. i just hope it stays that way.

thanx Jan