废话少说 先看看他的参数 |
呵呵 其实 写代码的时候 公式直接简化就得啦 如果测量要求不怎么高的话 呵呵(其实高也高不了 呵呵) 我们都喜欢简单 简单明了 嘿嘿 简化的公式: vu16 Temperature= (1.42 - ADC_Value*3.3/4096)*1000/4.35 + 25; |
呵呵 重新说一下 过程: 1. 初始化ADC 初始化DMA (大家可以参考马七的ADC教程 点击这里) 2. ADC_TempSensorVrefintCmd(ENABLE); 这个要开启哦 使能温度传感器和内部参考电压通道 3. 简单的数字滤波一下检测到的ADC的值 4. 按照刚才列出的公式计算 就OK啦 呵呵 第二步是做什么的呢? 看这个图就晓得啦 |
贴一下初始化的函数 /******************************************************************************* * 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); } |
这个是抄袭马七的均值数字滤波函数 呵呵 /******************************************************************************* * 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; } |
转换结果 往串口发送显示 (写的很烂哈) 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")); |
上一篇:STM32开发板入门教程(六) - I2C--24Cxx
下一篇:STM32笔记---DMA(USART)的演示
推荐阅读最新更新时间:2024-03-16 14:59