STM32
直播中

李刚

7年用户 1296经验值
私信 关注
[问答]

AD程序一直卡在校准的位置,怎么破?

                                                                                                     #include "bsp_adc.h"

void ADC1_IN1_Config(void)
{
         unsigned int  calibration_value = 0;
        GPIO_InitTypeDef    GPIO_InitStructure;
        ADC_InitTypeDef       ADC_InitStructure;
  ADC_CommonInitTypeDef ADC_CommonInitStructure;
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
        
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOA,  GPIO_InitStructure);
        
        


    /* Configure the ADC clock */
    RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div1);

    /* Enable ADC4 clock */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);
        
        ADC_StructInit( ADC_InitStructure);

        /* Calibration procedure */
        ADC_VoltageRegulatorCmd(ADC1, ENABLE);

        ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single);
        ADC_StartCalibration(ADC1);
        
        while(ADC_GetCalibrationStatus(ADC1) != RESET );
        
        calibration_value = ADC_GetCalibrationValue(ADC1);

    /* Configure the ADC4 in continuous mode */
    ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;                                                                    
    ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode;                    
    ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;            
    ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_OneShot;                  
    ADC_CommonInitStructure.ADC_TwoSamplingDelay = 0;      
    ADC_CommonInit(ADC1,  ADC_CommonInitStructure);

    ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable;
    ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
    ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;         
    ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;
    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
    ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;
    ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable;  
    ADC_InitStructure.ADC_NbrOfRegChannel = 1;
    ADC_Init(ADC1,  ADC_InitStructure);

     /* ADC4 regular channel5 configuration */
    ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_181Cycles5);//2é?ùê±???a21.5us

    /* Enable EOC interrupt */
         ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);

    /* Enable ADC4 */
    ADC_Cmd(ADC1, ENABLE);

    /* wait for ADRDY */
    while(ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY) == RESET);
    GPIO_ResetBits(GPIOB,GPIO_Pin_3);
    /* ADC4 start Conversion */
//     ADC_StartConversion(ADC4);   
}
主函数调用ADC1_IN1_Config(),结果程序一直卡在while(ADC_GetCalibrationStatus(ADC1) != RESET );这条AD校准语句上面,为何?


回帖(1)

cherr番茄

2024-5-14 16:56:57
当AD程序一直卡在校准的位置时,可以尝试以下几个步骤来解决问题:

1. 检查硬件连接:首先,确保所有硬件设备(如传感器、放大器等)都已正确连接到计算机。检查电缆是否松动或损坏,如果有问题,请更换或重新连接。

2. 检查软件设置:检查AD程序的设置,确保所有参数(如采样率、分辨率等)都已正确配置。如果不确定,请查阅设备手册或联系技术支持。

3. 更新驱动程序:确保计算机上的驱动程序是最新的。过时的驱动程序可能会导致程序卡住或无法正常工作。访问设备制造商的官方网站,下载并安装最新的驱动程序。

4. 重启计算机:有时候,简单地重启计算机可以解决许多问题。关闭计算机,然后重新启动,看看问题是否得到解决。

5. 检查系统资源:确保计算机有足够的资源(如CPU、内存等)来运行AD程序。如果资源不足,程序可能会变得缓慢或卡住。关闭不必要的应用程序,释放资源,然后再次尝试运行AD程序。

6. 检查程序兼容性:确保AD程序与您的操作系统兼容。如果程序是为旧版本的操作系统设计的,可能需要更新或寻找一个兼容的版本。

7. 重新安装程序:如果以上方法都无法解决问题,尝试卸载AD程序,然后重新安装。这可以解决由于安装错误或损坏的文件导致的问题。

8. 寻求技术支持:如果问题仍然存在,建议联系AD程序的制造商或技术支持部门。他们可能会提供更专业的解决方案或建议。

通过以上步骤,您应该能够解决AD程序卡在校准位置的问题。如果问题仍然存在,请考虑寻求专业技术支持。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分