廢話少說 先看看他的參數(shù)1.STM32內(nèi)部溫度傳感器與ADC的通道16相連,與ADC配合使用實(shí)現(xiàn)溫度測量;
2.測量范圍–40~125℃,精度±1.5℃。
3.溫度傳感器產(chǎn)生一個隨溫度線性變化的電壓,轉(zhuǎn)換范圍在2V < VDDA < 3.6V之間。
本文引用地址:http://www.ex-cimer.com/article/201611/322416.htm轉(zhuǎn)換公式如下圖所示:
呵呵 其實(shí) 寫代碼的時候 公式直接簡化就得啦如果測量要求不怎么高的話 呵呵(其實(shí)高也高不了 呵呵)
我們都喜歡簡單 簡單明了嘿嘿
簡化的公式:vu16 Temperature= (1.42 - ADC_Value*3.3/4096)*1000/4.35 + 25;
呵呵重新說一下 過程:
1. 初始化ADC初始化DMA (大家可以參考馬七的ADC教程 點(diǎn)擊這里)
2.ADC_TempSensorVrefintCmd(ENABLE);這個要開啟哦使能溫度傳感器和內(nèi)部參考電壓通道
3. 簡單的數(shù)字濾波一下檢測到的ADC的值
4. 按照剛才列出的公式計(jì)算就OK啦 呵呵
第二步是做什么的呢?看這個圖就曉得啦
貼一下初始化的函數(shù)
void ADC_Configuration(void)
{
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADCConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 1;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
DMA_Cmd(DMA1_Channel1, ENABLE);
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
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_55Cycles5);
ADC_TempSensorVrefintCmd(ENABLE);
ADC_DMACmd(ADC1, ENABLE);
ADC_Cmd(ADC1, ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
這個是抄襲馬七的均值數(shù)字濾波函數(shù) 呵呵
u16 ADC_Filter(void)
{
u16 result=0;
u8 i;
for(i=16;i>0;i--)
{
Delay_Ms(1);
result += ADCConvertedValue;
}
return result/16;
}
轉(zhuǎn)換結(jié)果 往串口發(fā)送顯示 (寫的很爛哈)
ADC_Value = ADC_filter();
vu16 Temperature= (1.42 - ADC_Value*3.3/4096)*1000/4.35 + 25;
ADC_Value = Temperature;
a = ADC_Value/1000;
b = (ADC_Value - a*1000)/100;
c = (ADC_Value - a*1000 - b*100)/10;
d = ADC_Value - a*1000 - b*100 - c*10;
Uart1_PutString("STM32 Chip Temperature = ",strlen("STM32 Chip Temperature = "));
Uart1_PutChar(a+0);
Uart1_PutChar(b+0);
Uart1_PutChar(c+0);
Uart1_PutChar(d+0);
Uart1_PutString(" C",strlen(" C"));
評論