ldj2000 发表于 2019-11-14 17:31:42

STM32L083读取内部温度,AD不校准可以,校准后为负,求助!

STM32L083读取内部温度,AD不校准可以读出现在温度18.3度,校准后温度为负了,-13.42.有没有朋友遇到过这个问题,求助!
AD校准后,测试到的VREF值非常准确3.298 V,其他输入电压也很准,就是温度不正确了。
校准程序如下:
if (HAL_ADCEx_Calibration_Start(&hadc, ADC_SINGLE_ENDED) !=HAL_OK)
{
    printf("\r\nAD Calibration fail\r\n");      
}

Paderboy 发表于 2019-11-14 21:39:08


Temperature configuration code example
/* (1) Select HSI16 by writing 00 in CKMODE (reset value) */
/* (2) Select continuous mode */
/* (3) Select CHSEL18 for temperature sensor */
/* (4) Select a sampling mode of 111 i.e. 239.5 ADC clk to be greater
than 2.2us */
/* (5) Wake-up the Temperature sensor (only for Temp sensor and
VRefInt) */
//ADC1->CFGR2 &= ~ADC_CFGR2_CKMODE; /* (1) */
ADC1->CFGR1 |=ADC_CFGR1_CONT; /* (2) */
ADC1->CHSELR =ADC_CHSELR_CHSEL18; /* (3) */
ADC1->SMPR |=ADC_SMPR_SMP; /* (4) */
ADC->CCR |=ADC_CCR_TSEN; /* (5) */

#define TEMP130_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FF8007E))
#define TEMP30_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FF8007A))
#define VDD_CALIB ((uint16_t) (300))
#define VDD_APPLI ((uint16_t) (330))
int32_t ComputeTemperature(uint32_t measure)
{
int32_t temperature;
temperature = ((measure *VDD_APPLI /VDD_CALIB)- (int32_t) *TEMP30_CAL_ADDR );
temperature =temperature * (int32_t)(130 - 30);
temperature =temperature / (int32_t)(*TEMP130_CAL_ADDR-*TEMP30_CAL_ADDR);
temperature =temperature + 30;
return(temperature);
}


aiherong 发表于 2019-11-15 04:06:38

不知你校验步骤是否正确,好像先开启AD转换器、重置校准寄存器(软件写1)并一直等其硬件清零,再才是校验ADC,同样要等到其硬件清零此位才算校验完成。在此之前设置RCC有一项专门设置AD的分频系数,还有要用右对齐,禁止触发检测,独立模式非扫描,不要开启连续转换;
读温度时正负号是依据getadcvalue值大于还是小于零决定,关键是值的计算准确

ldj2000 发表于 2019-11-15 15:00:25

Paderboy 发表于 2019-11-14 21:39
Temperature configuration code example
/* (1) Select HSI16 by writing 00 in CKMODE (reset value) */ ...

非常感谢!在static void MX_ADC_Init(void)初始化函数最后增加如下两行就可以了:
                ADC1->SMPR |=ADC_SMPR_SMP;
                ADC->CCR |=ADC_CCR_TSEN;

ldj2000 发表于 2019-11-15 15:02:24

非常感谢,在AD的初始化函数里面增加:
                ADC1->SMPR |=ADC_SMPR_SMP;
                ADC->CCR |=ADC_CCR_TSEN;
就可以了,我试了增加第一个ADC1->SMPR |=ADC_SMPR_SMP;其实就可以了。意思是我的温度采样速度太快了吗?
页: [1]
查看完整版本: STM32L083读取内部温度,AD不校准可以,校准后为负,求助!