ADC1、ADC2、ADC3设置之后,进行Calibration:
/* ADC1: Enable & Calibration */
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 reset calibration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
/* ADC2: Enable & Calibration */
/* Enable ADC2 */
ADC_Cmd(ADC2, ENABLE);
/* Enable ADC2 reset calibration register */
ADC_ResetCalibration(ADC2);
/* Check the end of ADC2 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC2));
/* Start ADC2 calibration */
ADC_StartCalibration(ADC2);
/* Check the end of ADC2 calibration */
while(ADC_GetCalibrationStatus(ADC2));
/* ADC3: Enable & Calibration */
/* Enable ADC3 */
ADC_Cmd(ADC3, ENABLE);
/* Enable ADC3 reset calibration register */
ADC_ResetCalibration(ADC3);
/* Check the end of ADC3 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC3));
/* Start ADC3 calibration */
ADC_StartCalibration(ADC3);
/* Check the end of ADC3 calibration */
while(ADC_GetCalibrationStatus(ADC3));
Run,然后就在 while(ADC_GetResetCalibrationStatus(ADC3));上死循环了。
查看stm32f10x_adc.c,找到ADC_ResetCalibration和ADC_GetResetCalibrationStatus:
void ADC_ResetCalibration(ADC_TypeDef* ADCx)
{
/* Check the parameters */
assert_param(IS_ADC_ALL_PERIPH(ADCx));
/* Resets the selected ADC calibration registers */
ADCx->CR2 |= CR2_RSTCAL_Set;
}
FlagStatus ADC_GetResetCalibrationStatus(ADC_TypeDef* ADCx)
{
FlagStatus bitstatus = RESET;
/* Check the parameters */
assert_param(IS_ADC_ALL_PERIPH(ADCx));
/* Check the status of RSTCAL bit */
if ((ADCx->CR2 & CR2_RSTCAL_Set) != (uint32_t)RESET)
{
/* RSTCAL bit is set */
bitstatus = SET;
}
else
{
/* RSTCAL bit is reset */
bitstatus = RESET;
}
/* Return the RSTCAL bit status */
return bitstatus;
}
用Watchwindow查看,发现:
ADC1的CR2末四位:0011,其中RSTCAL为0;
ADC2的CR2末四位:0011,其中RSTCAL为0;
ADC3的CR2末四位:1011,其中RSTCAL为1.
Reference manual关于RSTCAL位的说明如下:This bit is set by software and cleared by hardware. It is cleared after the calibration registers are initialized.
就是说ADC3的Calibration功能在“ADCx->CR2 |= CR2_RSTCAL_Set;”之后没有“cleared by hardware”。
然而,ADC1、ADC2均没有出现这个问题,实在感到不解。本人初学,望各位大侠指导一下。 |