有关STM32F0ADC库函数中Timeout用法的问题
我用STM32Cubemx生成keil项目,用到了ADC,于是查看stm32f0xx_hal_adc.c.中的HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)函数,不明白Timeout参数是干什么用的,,Timeout我试过用不同的值,但是效果都一样,没什么区别该函数如下:
/**
* @briefWait for regular group conversion to be completed.
* @paramhadc: ADC handle
* @paramTimeout: Timeout value in millisecond.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
{
uint32_t tickstart;
uint32_t tmp_Flag_EOC;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
/* If end of conversion selected to end of sequence */
if (hadc->Init.EOCSelection == EOC_SEQ_CONV)
{
tmp_Flag_EOC = ADC_FLAG_EOS;
}
/* If end of conversion selected to end of each conversion */
else /* EOC_SINGLE_CONV */
{
tmp_Flag_EOC = (ADC_FLAG_EOC | ADC_FLAG_EOS);
}
/* Get timeout */
tickstart = HAL_GetTick();
/* Wait until End of Conversion flag is raised */
while(HAL_IS_BIT_CLR(hadc->Instance->ISR, tmp_Flag_EOC))
{
/* Check if timeout is disabled (set to infinite wait) */
if(Timeout != HAL_MAX_DELAY)
{
if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
{
/* Update ADC state machine to timeout */
hadc->State = HAL_ADC_STATE_TIMEOUT;
/* Process unlocked */
__HAL_UNLOCK(hadc);
return HAL_ERROR;
}
}
}
/* Clear end of conversion flag of regular group if low power feature */
/* "LowPowerAutoWait " is disabled, to not interfere with this feature */
/* until data register is read using function HAL_ADC_GetValue(). */
if (hadc->Init.LowPowerAutoWait == DISABLE)
{
/* Clear regular group conversion flag */
__HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_EOC | ADC_FLAG_EOS));
}
/* Update state machine on conversion status if not in error state */
if(hadc->State != HAL_ADC_STATE_ERROR)
{
/* Change ADC state */
hadc->State = HAL_ADC_STATE_EOC_REG;
}
/* Return ADC state */
return HAL_OK;
}
请问Timeout有什么用? 打断while(HAL_IS_BIT_CLR(hadc->Instance->ISR, tmp_Flag_EOC)),退出这个loop的条件,代码更健壮。 异常情况下的超时退出
页:
[1]