新手入门
- 积分
- 14
- 金钱
- 14
- 注册时间
- 2014-6-14
- 在线时间
- 6 小时
|
10金钱
AdcHandle.Instance = ADC1;
AdcHandle.Init.OversamplingMode = DISABLE;
AdcHandle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV1;
AdcHandle.Init.LowPowerAutoPowerOff = DISABLE;
AdcHandle.Init.LowPowerFrequencyMode = ENABLE;
AdcHandle.Init.LowPowerAutoWait = DISABLE;
AdcHandle.Init.Resolution = ADC_RESOLUTION_12B;
AdcHandle.Init.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
AdcHandle.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
AdcHandle.Init.ContinuousConvMode = ENABLE;
AdcHandle.Init.DiscontinuousConvMode = DISABLE;
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
AdcHandle.Init.DMAContinuousRequests = DISABLE;
/* Initialize ADC peripheral according to the passed parameters */
if (HAL_ADC_Init(&AdcHandle) != HAL_OK)
{
Error_Handler();
}
/* ### - 2 - Start calibration ############################################ */
if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED) != HAL_OK)
{
Error_Handler();
}
while(1)
{
sConfig.Channel = ADC_CHANNEL_3;
sConfig.Rank = 1;
HAL_ADC_ConfigChannel(&AdcHandle, &sConfig);
HAL_ADC_Start(&AdcHandle);
while(__HAL_ADC_GET_FLAG(&AdcHandle,ADC_FLAG_EOC) == RESET){;}
ADC3 = HAL_ADC_GetValue(&AdcHandle);
sConfig.Channel = ADC_CHANNEL_4;
sConfig.Rank = 1;
HAL_ADC_ConfigChannel(&AdcHandle, &sConfig);
HAL_ADC_Start(&AdcHandle);
while(__HAL_ADC_GET_FLAG(&AdcHandle,ADC_FLAG_EOC) == RESET){;}
ADC4 = HAL_ADC_GetValue(&AdcHandle);
}
上面是ADC部分的主要代码,仿真时ADC3和ADC4读出来的数据都是adc3的值。
HAL_ADC_ConfigChannel(&AdcHandle, &sConfig);这个函数不起作用。
仿真进入该函数
if (ADC_IS_CONVERSION_ONGOING_REGULAR(hadc) != RESET)
{
/* Update ADC state machine to error */
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
/* Process unlocked */
__HAL_UNLOCK(hadc);
return HAL_ERROR;
}
由于这个返回错误,没有执行后面切换通道的赋值。
对于ADC_IS_CONVERSION_ONGOING_REGULAR(hadc)函数不是很理解。
请大神帮忙看下需要怎么修改,谢谢。
|
|