2017-03-23 11:20 PM
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 conversion4 { count++; }5 capVL = (uint16_t)ADC1->DR; // read value6 ADC1->CR |= (uint32_t)ADC_CR_ADSTART; // start second conversion7 count = 0;8 while(((ADC1->ISR & ADC_ISR_EOC) == (uint32_t)reset) && (count < timeout)) // wait for end of conversion9 { count++; }10// while(count < timeout) count++;11 capVH = (uint16_t)ADC1->DR; // read valueif 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-access2017-03-24 12:45 AM
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
2017-03-24 06:07 PM
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:
thanx
2017-03-25 07:37 AM
Which device is used?
2017-03-25 11:57 AM
it's a nucleo board with a stm32f070rb mcu
2017-03-25 12:18 PM
Just to make sure, try by replacing 'reset' by 0
2017-03-25 12:56 PM
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...
2017-03-25 09:22 PM
well ok after 6 hours i got a new IDE and no it's still freezing at line 8
2017-03-26 01:43 AM
Post a minimal but complete compilable example exhibiting the problem.
JW
2017-03-26 06:44 PM
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