2020-07-31 08:30 AM
Hello,
In my application I want to get the ADC voltage - waiting indefinitely until the operation completes. Will this code work ?
while ( HAL_ADC_PollForConversion ( & hadc1 , 1000 ) == HAL_TIMEOUT );
2020-07-31 08:43 AM
No need to external while loop, HAL_ADC_PollForConversion has a while loop inside. Just use
HAL_ADC_PollForConversion ( & hadc1 , 1000 );
MCU waits at this line until EOC flag sets.
2020-07-31 08:44 AM
After conversion completed, use HAL_ADC_GetValue to read ADC value.
2020-07-31 09:02 AM
What does the "1000" value do inside the function ? Isn't it the timeout ?
I want it to wait indefinitely - not just 1000 cycles...
2020-07-31 03:33 PM
To wait indefinitely, use HAL_MAX_DELAY as the delay. This is #defined as 0xFFFFFFFF.
The code you linked will also work. I feel like I wrote that in a post not too long ago which I can't find.
2020-07-31 07:12 PM
The timeout value can be a uint32_t and the unit is milliseconds not cycles.
2020-08-01 02:34 AM
Thanks,
But either way, my goal is indefinite timeout.
So what I thought about is using:
while ( HAL_ADC_PollForConversion ( & hadc1 , 1000 ) == HAL_TIMEOUT );
Will the above code case an infinite loop until a conversion is finished ? This is what I want...
If yes, I don't really understand prain's comment:
"No need to external while loop, HAL_ADC_PollForConversion has a while loop inside"
Without the external loop - won't the internal while loop inside "HAL_ADC_PollForConversion" exit after the timeout is reached ?
2020-08-01 05:25 AM
your approach is correct but I can not figure out why you need to wait infinitely.
2020-08-01 12:07 PM
Because I need to wait for the ADC to give me a conversion result...no matter how long it takes.
What are you suggesting to do instead ?
2020-08-01 12:13 PM
> What are you suggesting to do instead ?
@skon.1
I answered you yesterday. See below.