STM32F0多路ADC采樣中的BUG和解決方案
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生產(chǎn)的ADC無(wú)法配置多路采樣,多路采樣采集值不對(duì),研究后發(fā)現(xiàn)是底層函數(shù)沒(méi)有將CHANNEL清零導(dǎo)致的
只需要在函數(shù)中增加 hadc.Instance->CHSELR = 0; 手動(dòng)清0 寄存器即可。