ADC getting stuck while checking for EOC flag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-27 6:33 AM
Im trying to write code that will average samples from the ADC of an STM32F01K6. I am starting a conversion and waiting while the conversion takes place by writing a while loop which checks the finish flag
ADC1->CR |= ADC_CR_ADSTART;
while(((ADC1->ISR) & 0b00000100)!=0)
{
}
for(j=0;j<4;j++)
{
ADC_result_pre[i][j] = ADC1->DR; //fetch adc data
}
ADC_result[i]=(ADC_result_pre[i][0]+ADC_result_pre[i][1]+ADC_result_pre[i][2]+ADC_result_pre[i][3])/4;
switch(ADC1->CHSELR) //switch dac channel to the next
{
case 0b1:
ADC1 ->CHSELR = 0b10;
i=1;
break;
case 0b10:
ADC1 ->CHSELR = 0b1;
i=0;
break;
}
If i write code which doesn't wait for the EOC flag, the ADC works fine. However, with this code it gets stuck in the while loop, the EOC flag never appears. Where have I gone wrong?
Solved! Go to Solution.
- Labels:
-
ADC
-
STM32F0 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-27 8:46 AM
Your code waits for the EOC flag to be reset, not set. Your logic is backwards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-27 8:46 AM
Your code waits for the EOC flag to be reset, not set. Your logic is backwards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-28 3:35 AM
thanks, but if I make it
while(((ADC1->ISR) & 0b00000100)!=1)
{
}
it still gets stuck in the loop ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-28 3:39 AM
> while(((ADC1->ISR) & 0b00000100)!=1)
something AND 0b00000100 can't never result in 1
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-28 3:44 AM
oh yeah, thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-30 8:34 AM
Hello @deep_rune​ ,
Please select the post as a "Best Answer" if it solved your problem or answered your question.
Best Regards,
Imen
Thanks
Imen
