I want to read 4 ADC channels in continuous scan mode.
I am using ADC interrupt to read from the ADC data register.
Here is my initialization:
hadc3.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
hadc3.Init.Resolution = ADC_RESOLUTION_12B;
hadc3.Init.ScanConvMode = ENABLE;
hadc3.Init.ContinuousConvMode = ENABLE;
hadc3.Init.DiscontinuousConvMode = DISABLE;
hadc3.Init.ExternalTrigConvEdge =
ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc3.Init.NbrOfConversion = 4;
hadc3.Init.DMAContinuousRequests = DISABLE;
hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
I have set a breakpoint in the interrupt handler.
As soon as I start debugging, the execution goes into the interrupt handler and the OVR
bit is found to be set in the status register.
To proceed with the normal execution I have to re-trigger the ADC via this line of code:
void HAL_ADC_ErrorCallback(ADC_HandleTypeDef* hadc)
{
hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART;
}
in the ErrorCallback()
function.
The readings are coming fine but I cannot understand why the overrun bit is set at every cycle of conversion.