ADC getting stuck while checking for EOC flag
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?