这里是main中部分代码和ADC初始化函数,我在STM32F103ZET6开发板上读温度正常,用GD32F103读就高出来20度,什么原因呢?
while(1)
{
ad=0;
for(i=0;i<50;i++)
{
ADC_SoftwareStartConvCmd(ADC1,ENABLE);
while(!ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC));
ad=ad+ADC_GetConversionValue(ADC1);
}
ad=ad/50;
temputure = (1.43-3.3/4095*ad)/0.0043+25;
printf("温度 =%f\r\n",(1.43-3.3/4095*ad)/0.0043+25);//根据计算公式编写
void ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_InitStructure.ADC_Mode=ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode=DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode=DISABLE;
ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel=1;
ADC_Init(ADC1,&ADC_InitStructure);
ADC_RegularChannelConfig(ADC1,ADC_Channel_16,1,ADC_SampleTime_239Cycles5);//温度传感器必须使用16通道,这是固定的
ADC_TempSensorVrefintCmd(ENABLE);//温度传感器使能
ADC_Cmd(ADC1,ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
ADC_SoftwareStartConvCmd(ADC1,ENABLE);
} |