如何读取多通道ADC值?

时间:2017-01-17 13:05:45

标签: microcontroller stm32 adc hal

我可以使用此代码ADCValue = HAL_ADC_GetValue(&hadc1);从ADC1_IN1通道读取ADC值,但ADC1端口(可以看到图片)有很多通道。如何读取ADC1_IN2中的值?如何在代码中描述通道2?

ADC1 port

1 个答案:

答案 0 :(得分:2)

您可以通过HAL_ADC_ConfigChannel功能设置ADC通道:

ADC_ChannelConfTypeDef sConfig;
sConfig.Channel = ADC_CHANNEL_2; // ADC Channel
sConfig.Rank = 1; //Rank (1-16) Rank: The rank in the regular group sequencer.
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; //ADC Sampling Times
sConfig.Offset = 0; // Reserved

if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
    //Error
}

Description of STM32F4xx HAL drivers