STM32F4 ADC overrun errors
Hi, I have a problem configuring ADC1 on an STM32F429 to do a regular scan of a sequence of 4 channels without using DMA. The fourth channel is the internal temperature sensor. The third channel to be scanned always gives an overrun error (ADC_SR.OVR=1). We are also configuring two other channels as injected channels at the same time (not shown in the code below). The initialization code looks like this (using the CMSIS peripheral access layer) :
ADC1->CR1 |= ADC_CR1_SCAN;
ADC1->SQR1 |= 3 << ADC_SQR1_L_Pos;
ADC1->SQR3 |=
(12U << ADC_SQR3_SQ1_Pos) |
(3U << ADC_SQR3_SQ2_Pos) |
(4U << ADC_SQR3_SQ3_Pos) |
(18U << ADC_SQR3_SQ4_Pos);
ADC123_COMMON->CCR |=
ADC_CCR_TSVREFE;
ADC1->CR2 |= ADC_CR2_EOCS;
// Sampling time = 15 cycles for the channels we use
ADC1->SMPR1 = 00100000101;
ADC1->SMPR2 = 00000011001;
ADC1->CR2 |= ADC_CR2_ADON;and the sampling code, called every 220ms, looks like this:
int i = 0;
Bool Overrun = FALSE;
ADC1->CR2 |= ADC_CR2_SWSTART;
do
{
if(Overrun)
ADC1->CR2 |= ADC_CR2_SWSTART;
while ((ADC1->SR & ADC_SR_EOC) == 0)
{
if(ADC1->SR & ADC_SR_OVR)
{
ADC1->SR &= ~(ADC_SR_OVR | ADC_SR_EOC);
Overrun = TRUE;
break;
}
else
{
Overrun = FALSE;
}
}
if(!Overrun)
{
ADCValues[i] = ADC1->DR;
}
i++;
} while (i < 4);
}So we always read the data register immediately after ADC_SR.EOC is set, but for some reason we are still getting an overrun error for one of the channels. If I only include the first two channels in the sequence there are no errors. If I increase the number of cycles for some of the channels to the max (480 cycles) it seems to make the error go away, but I'd like to understand better what is going on here. Can anyone help?
Thanks,
Scott.
