<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > STM32 之 內(nèi)部溫度傳感器

          STM32 之 內(nèi)部溫度傳感器

          作者: 時(shí)間:2016-12-03 來(lái)源:網(wǎng)絡(luò) 收藏
          和ADC的設(shè)置基本相同,算是ADC的擴(kuò)展應(yīng)用。

          只是在計(jì)算方法上有變化,在adc的初始化程序里面做一些變動(dòng)就可以了。

          本文引用地址:http://www.ex-cimer.com/article/201612/325139.htm

          包含函數(shù):

          (1)Main

          C語(yǔ)言:Codee#14690

          /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
          + 實(shí)驗(yàn)平臺(tái) : ST 官方三合一套件
          + 硬件 : STM32F103C8T6
          + 開(kāi)發(fā)平臺(tái) : IAR For ARM 5.40
          + 仿真器 : J-Link
          + 日期 : 2010-10-28
          + 頻率 :HSE = 8MHz ,主頻 = 72MHz
          ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

          #include "includes.h"
          #include "stdio.h"
          /*******************************************************************************
          == 變量聲明 ==
          *******************************************************************************/
          floatADC_Value,Tem;
          unsignedchara=0;
          unsignedcharb=0;
          unsignedcharc=0;
          unsignedchard=0;

          /*******************************************************************************
          == Main 函數(shù) ==
          *******************************************************************************/
          voidmain(void)
          {
          //---- 初始化 ------------------------------------------------------
          RCC_Configuration();//配置系統(tǒng)時(shí)鐘
          NVIC_Configuration();//配置 NVIC 和 Vector Table
          SysTick_Config();//配置SysTick的精確延時(shí)

          GPIO_Configuration();
          UART1_Configuration();
          AD_Configration();
          DMA_Configration();


          //---- 任務(wù)開(kāi)始 ----------------------------------------------------
          LED1_HIGH;LED2_HIGH;LED3_HIGH;LED4_HIGH;// 初始化讓燈全滅

          Uart1_PutString("===== douzi STM32 @ Temperature =====rn",39);

          while(1)
          {// 這里只選采集的10個(gè)數(shù)據(jù)中的一個(gè),應(yīng)該做一些算法進(jìn)行濾波才好
          ADC_Value=(float)(sys_analog[5])*330/409600;// 計(jì)算公式datasheet上可以找到,但是我沒(méi)找到。
          Tem=(1.42-ADC_Value)*1000/4.35+25;

          Tem=Tem*100;// ADC是12位的,這里數(shù)據(jù)類型轉(zhuǎn)換有問(wèn)題
          a=Tem/1000;
          b=(Tem-a*1000)/100;
          c=(Tem-a*1000-b*100)/10;
          d=Tem-a*1000-b*100-c*10;

          Uart1_PutChar(a+0);
          Uart1_PutChar(b+0);
          Uart1_PutString(".",1);
          Uart1_PutChar(c+0);
          Uart1_PutChar(d+0);
          Uart1_PutString(" Cn",3);

          Delay_Ms(1000);
          }
          }

          (2)在ADC初始化函數(shù)里要變動(dòng)些內(nèi)容,關(guān)于溫度傳感器

          C語(yǔ)言:Codee#14691
          /*******************************************************************************
          * Function Name : AD_Configration
          * Description : Configures the ADC1
          * Input : None
          * Output : None
          * Return : None
          *******************************************************************************/
          voidAD_Configration(void)
          {
          ADC_InitTypeDefADC_InitStructure_ADC1;

          /* Resets ADC1 */
          ADC_DeInit(ADC1);

          ADC_InitStructure_ADC1.ADC_Mode=ADC_Mode_Independent;// 配置ADC1 工作在獨(dú)立模式
          ADC_InitStructure_ADC1.ADC_ScanConvMode=ENABLE;// 配置ADC1 模數(shù)轉(zhuǎn)換工作在掃描模式(多通道模式)
          ADC_InitStructure_ADC1.ADC_ContinuousConvMode=ENABLE;// 配置ADC1 模數(shù)轉(zhuǎn)換工作在連續(xù)模式
          ADC_InitStructure_ADC1.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None;// 配置ADC1 模數(shù)轉(zhuǎn)換有軟件方式啟動(dòng)而非中斷方式
          ADC_InitStructure_ADC1.ADC_DataAlign=ADC_DataAlign_Right;// 配置ADC1 模數(shù)轉(zhuǎn)換數(shù)據(jù)對(duì)齊方式為右對(duì)齊
          ADC_InitStructure_ADC1.ADC_NbrOfChannel=1;// 配置ADC1 模數(shù)轉(zhuǎn)換的通道數(shù)目 為 1個(gè)通道
          ADC_Init(ADC1,&ADC_InitStructure_ADC1);// 配置ADC1 初始化
          //常規(guī)轉(zhuǎn)換序列1:通道10
          ADC_RegularChannelConfig(ADC1,ADC_Channel_16,1,ADC_SampleTime_239Cycles5);// 配置為 ADC1,通道1,1個(gè)通道,采樣時(shí)間為239.5個(gè)周期,周期越長(zhǎng)采集的信號(hào)越準(zhǔn)越穩(wěn)
          // 對(duì)應(yīng)的管教所對(duì)應(yīng)的ADC通道時(shí)對(duì)應(yīng)的,一定不要搞錯(cuò)!
          /* Enable the temperature sensor and vref internal channel */
          ADC_TempSensorVrefintCmd(ENABLE);// 使能溫度傳感器內(nèi)部參考電壓通道

          ADC_DMACmd(ADC1,ENABLE);// 使能ADC1的DMA請(qǐng)求

          ADC_Cmd(ADC1,ENABLE);// 使能ADC1

          /* Enable ADC1 reset calibaration register */
          ADC_ResetCalibration(ADC1);// 重置ADC1的校準(zhǔn)寄存器
          /* Check the end of ADC1 reset calibration register */
          while(ADC_GetResetCalibrationStatus(ADC1));// 檢測(cè)是否重置完畢

          /* Start ADC1 calibaration */
          ADC_StartCalibration(ADC1);// 開(kāi)始校準(zhǔn) ADC1
          /* Check the end of ADC1 calibration */
          while(ADC_GetCalibrationStatus(ADC1));// 檢測(cè)是否校準(zhǔn)完畢

          /* Start ADC1 Software Conversion */
          ADC_SoftwareStartConvCmd(ADC1,ENABLE);// 軟件使能ADC1的轉(zhuǎn)換
          }




          關(guān)鍵詞: STM32內(nèi)部溫度傳感

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();