uint32_t ADC_Detect(uint32_t AD_Channel)
{
hadc.Instance->CHSELR = 0;
ADC_ChannelConfTypeDef sConfig;
sConfig.Channel = AD_Channel;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
sConfig.SamplingTIme = ADC_SAMPLETIME_1CYCLE_5;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
uint32_t ADC_result;
/*ADC START*/
if(HAL_ADC_Start(&hadc)!=HAL_OK)
{
while(1)
{
}
}
/*Wait for ADC completed*/
if (HAL_ADC_PollForConversion(&hadc, 10) != HAL_OK)
{
while(1)
{
}
}
else
{
/*Get the converted value of regular channel*/
ADC_result = HAL_ADC_GetValue(&hadc);
HAL_ADC_Stop(&hadc);
//ADC_result =((ADC_result*3300)>>8);
return ADC_result;
}
}
运用CUBE出产的ADC无法装备多路采样,多路采样收集值不对,研讨后发现是底层函数没有将CHANNEL清零导致的
只需要在函数中添加 hadc.Instance->CHSELR = 0; 手动清0 寄存器即可。