STM32F40x 内部温度获取

#include "ADC.h"


//user guide
// in board init, call function: adc_init();
// get_internal_temperture(); get tempertare, uinit℃


static void AdcPinComInit(void)
{
ADC_CommonInitTypeDef   ADC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE);

ADC_InitStructure.ADC_Mode = ADC_DualMode_RegSimult;
ADC_InitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_InitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_InitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_6Cycles;
ADC_CommonInit(&ADC_InitStructure);
}


static void Adc1ChxConfig(void)
{
  ADC_InitTypeDef ADC_InitStructure;


ADC_TempSensorVrefintCmd(ENABLE);
  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;
  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
  ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfConversion = 1;
  ADC_Init(ADC1, &ADC_InitStructure);

ADC_ContinuousModeCmd(ADC1, ENABLE);
ADC_Cmd(ADC1, ENABLE);
}


void adc_init(void)
{
AdcPinComInit();
Adc1ChxConfig();
}


uint16_t get_internal_temperture(void)
{
uint16_t temp_adc_value;
uint16_t temperature;

ADC_TempSensorVrefintCmd(ENABLE);
ADC_RegularChannelConfig(ADC1, ADC_Channel_TempSensor, 1, ADC_SampleTime_15Cycles);
ADC_SoftwareStartConv(ADC1);
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));

temp_adc_value = ADC_GetConversionValue(ADC1);

// T = (Vsense -V15)/AVG_Slope +25 ,
//Vsense =  (adc_value *3.3)/4096, 12bit ADC
// V25 = 0.76,AVG_Slope = 2.5mV/℃
temperature = ((temp_adc_value * 3.3)/4096 - 0.76) *1000/2.5 + 25 ;
return temperature;

}


实际测量的值为40℃左右。


































































  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值