STM32開發(fā)板入門教程 - 內(nèi)部溫度傳感器
廢話少說 先看看他的參數(shù) |
呵呵 其實(shí) 寫代碼的時(shí)候 公式直接簡(jiǎn)化就得啦如果測(cè)量要求不怎么高的話 呵呵(其實(shí)高也高不了 呵呵) 我們都喜歡簡(jiǎn)單 簡(jiǎn)單明了嘿嘿 簡(jiǎn)化的公式:vu16 Temperature= (1.42 - ADC_Value*3.3/4096)*1000/4.35 + 25; |
呵呵重新說一下 過程: 1. 初始化ADC初始化DMA (大家可以參考馬七的ADC教程點(diǎn)擊這里) 2.ADC_TempSensorVrefintCmd(ENABLE); 這個(gè)要開啟哦使能溫度傳感器和內(nèi)部參考電壓通道 3. 簡(jiǎn)單的數(shù)字濾波一下檢測(cè)到的ADC的值 4. 按照剛才列出的公式計(jì)算就OK啦 呵呵 第二步是做什么的呢?看這個(gè)圖就曉得啦 |
貼一下初始化的函數(shù) /******************************************************************************* * Function Name: ADC_Configuration * Description : ADC_Configuration * Input : None * Output : None * Return : None *******************************************************************************/ void ADC_Configuration(void) { /* DMA1 channel1 configuration ----------------------------------------------*/ 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); /* Enable DMA1 channel1 */ DMA_Cmd(DMA1_Channel1, ENABLE); /* ADC1 configuration ------------------------------------------------------*/ 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); /* ADC1 regular channel14 configuration */ ADC_RegularChannelConfig(ADC1,ADC_Channel_16, 1, ADC_SampleTime_55Cycles5); /* Enable the temperature sensor and vref internal channel */ ADC_TempSensorVrefintCmd(ENABLE); /* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 reset calibaration register */ ADC_ResetCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibaration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); /* Start ADC1 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); } |
這個(gè)是抄襲馬七的均值數(shù)字濾波函數(shù) 呵呵 /******************************************************************************* * Function Name: ADC_Filter * Description : ADC_Filter * Input : None * Output : None * Return : ADC Converted Value *******************************************************************************/ 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/n",strlen(" C/n")); |
評(píng)論