Question
Multiple ADC's and single conversion STM32F030
Posted on December 11, 2015 at 15:00
Hello
I'm having a hard time getting multiple ADC's working on a STM32F I have 3 analog voltages I would like to read with the MCU. But not continuous. I would like to take 1 sample at a time and at different intervals. I use the HAL library for this project and it seems very hard to select a channel and take a reading. I use CubeMX for the initialisation and this is what it returns:void MX_ADC_Init(void)
{
ADC_ChannelConfTypeDef sConfig;
/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc.Instance = ADC1;
hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC;
hadc.Init.Resolution = ADC_RESOLUTION12b;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
hadc.Init.EOCSelection = EOC_SINGLE_CONV;
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;
hadc.Init.ContinuousConvMode = DISABLE;
hadc.Init.DiscontinuousConvMode = ENABLE;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc.Init.DMAContinuousRequests = DISABLE;
hadc.Init.Overrun = OVR_DATA_PRESERVED;
HAL_ADC_Init(&hadc);
/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_1;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_7;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_8;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_VREFINT;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
}
Then in the main function I use this to retreive a sample:
/* USER CODE BEGIN 3 */
HAL_ADC_Start(&hadc);
HAL_ADC_PollForConversion(&hadc, 1000);
adcSample = HAL_ADC_GetValue(&hadc);
HAL_ADC_Stop(&hadc);
}
/* USER CODE END 3 */
But this always returns the value of adc_channel_1 on PA0
What is the correct way to retrieve a sample from another channel?
My sincerely,
#adc #hal #f0