STM32F730xx ADC: EOC never set when reading VREFINT
Hello,
we want to read VREFINT to make our ADC measurements more accurate.
But the EOC bit is never set when selecting the ADC_CHANNEL_VREFINT channel.
PCLK2 is at 108MHz but ADC prescaler and sampling cycles are at max. so we assume there is no problem with the min. 10us sampling time.
The code below works for normal channels.
void MX_ADC1_Init(void)
{
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV8;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
Error_Handler();
}
uint8_t MX_ADC_Read(ADC_HandleTypeDef *hadc, uint32_t channel, uint32_t *val)
{
ADC_ChannelConfTypeDef sConfig = {};
sConfig.Channel = channel;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;
sConfig.Offset = 0;
if (!hadc)
return 0;
if (!val)
return 0;
if (HAL_ADC_ConfigChannel(hadc, &sConfig) != HAL_OK)
return 0;
if (HAL_ADC_Start(hadc) != HAL_OK)
return 0;
if (HAL_ADC_PollForConversion(hadc, 100) != HAL_OK)
return 0;
*val = HAL_ADC_GetValue(hadc);
HAL_ADC_Stop(hadc);
return 1;
}Here how we call MX_ADC_Read.
uint32_t val;
if (!MX_ADC_Read(&hadc1, ADC_CHANNEL_VREFINT, &val))
Error_Handler();Any idea what the problem could be?
Thanks
rengl