用
STM32L052采样AD,两个通道,其中一个通道要用过采样技术,通道的切换是在AD中断进行。请问是否每次都要校准HAL_ADCEx_Calibra
tion_Start()?而每次AD中断中,参数设置的时候,是否都要关中断HAL_ADC_Stop_IT() ,参数设置完在开中断HAL_ADC_Start_IT()?
/* ADC2 init function */
void MX_ADC2_Init(void)
{
ADC_ChannelConfTypeDef sConfig;
/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc.Instance = ADC1;
hadc.Init.OversamplingMode = DISABLE;
hadc.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV1;
hadc.Init.Resolution = ADC_RESOLUTION12b;
hadc.Init.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.ContinuousConvMode = DISABLE;
hadc.Init.DiscontinuousConvMode = ENABLE;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIG_EDGE_NONE;
hadc.Init.DMAContinuousRequests = DISABLE;
hadc.Init.EOCSelection = EOC_SINGLE_CONV;
hadc.Init.Overrun = OVR_DATA_PRESERVED;
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerFrequencyMode = ENABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;
HAL_ADC_Init(&hadc);
/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_2;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
}
/* ADC7 init function */
void MX_ADC7_Init(void)
{
ADC_ChannelConfTypeDef sConfig;
/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc.Instance = ADC1;
hadc.Init.OversamplingMode = ENABLE;
hadc.Init.Oversample.Ratio = ADC_OVERSAMPLING_RATIO_128;
hadc.Init.Oversample.RightBitShift = ADC_RIGHTBITSHIFT_3;
hadc.Init.Oversample.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
hadc.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV1;
hadc.Init.Resolution = ADC_RESOLUTION12b;
hadc.Init.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.ContinuousConvMode = DISABLE;
hadc.Init.DiscontinuousConvMode = ENABLE;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIG_EDGE_NONE;
hadc.Init.DMAContinuousRequests = DISABLE;
hadc.Init.EOCSelection = EOC_SINGLE_CONV;
hadc.Init.Overrun = OVR_DATA_PRESERVED;
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerFrequencyMode = ENABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;
HAL_ADC_Init(&hadc);
/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_7;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
}
一周热门 更多>