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 寄存器即可。
- Keil MDK破解過(guò)程詳解[2019-03-20 10:47:17]
- STM32F407之模擬I2C(二)之24C128[2019-03-20 10:47:17]
- STM32F1使用I/0模擬I2C接口[2019-03-20 10:47:17]
- STM32模擬I2C程序[2019-03-20 10:47:17]
- STM8S 模擬I2C程序[2019-03-20 10:47:17]
- 普通IO口模擬實(shí)現(xiàn)I2C通信及應(yīng)用解析[2019-03-20 10:47:17]