完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
说明
基于stm32f429,利用内置温度传感器和ADC外设,测量芯片工作温度,再通过DMA外设将ADC外设数据传到内存中,利用串口打印输出。(串口部分驱动代码省略) 通过暖风机测试,工作温度从24度左右上升至37度。 流程
#ifndef __BSP_ADC_H #define __BSP_ADC_H #include "stm32f4xx_gpio.h" #include "stm32f4xx_rcc.h" #include "stm32f4xx_adc.h" #define Temp_sensor_channel ADC_Channel_18 #define ADC1_Channel DMA_Channel_0 #define ADC1_DR_ADDR ((uint32_t)ADC1+0x4C) void Temp_Sensor_ADC_Init(void); ADC相关配置源文件 #include "bsp_adc.h" __IO uint16_t ADC_ConvertedValue; void Temp_Sensor_ADC_Config(void) { /*初始化DMA, ADC, ADC_Common结构体*/ ADC_InitTypeDef ADC_InitStruct; DMA_InitTypeDef DMAInitStruct; ADC_CommonInitTypeDef ADC_CommonInitStruct; /**************配置DMA************/ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); /*DMA配置如下*/ DMAInitStruct.DMA_BufferSize = 1; DMAInitStruct.DMA_Channel = DMA_Channel_0; DMAInitStruct.DMA_DIR = DMA_DIR_PeripheralToMemory; DMAInitStruct.DMA_FIFOMode = DMA_FIFOMode_Disable ; DMAInitStruct.DMA_FIFOThreshold = DMA_FIFOThreshold_Full ; DMAInitStruct.DMA_Memory0BaseAddr = (uint32_t)&(ADC_ConvertedValue); DMAInitStruct.DMA_MemoryBurst =DMA_MemoryBurst_Single ; DMAInitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord ; DMAInitStruct.DMA_MemoryInc =DMA_MemoryInc_Disable ; DMAInitStruct.DMA_Mode = DMA_Mode_Circular ; DMAInitStruct.DMA_PeripheralBaseAddr = ADC1_DR_ADDR; DMAInitStruct.DMA_PeripheralBurst = DMA_PeripheralBurst_Single ; DMAInitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord ; DMAInitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMAInitStruct.DMA_Priority =DMA_Priority_High; DMA_Init(DMA2_Stream0, &DMAInitStruct); DMA_Cmd(DMA2_Stream0, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); /*****************ADC_Common配置如下***********************/ ADC_CommonInitStruct.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; ADC_CommonInitStruct.ADC_Mode = ADC_Mode_Independent; ADC_CommonInitStruct.ADC_Prescaler = ADC_Prescaler_Div4; ADC_CommonInitStruct.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_20Cycles; ADC_CommonInit(&ADC_CommonInitStruct); ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b; ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStruct.ADC_ExternalTrigConv =ADC_ExternalTrigConv_T1_CC1 ; ADC_InitStruct.ADC_ExternalTrigConvEdge =ADC_ExternalTrigConvEdge_None; ADC_InitStruct.ADC_NbrOfConversion = 1; ADC_InitStruct.ADC_ScanConvMode = DISABLE; ADC_InitStruct.ADC_ContinuousConvMode = ENABLE; ADC_Init(ADC1, &ADC_InitStruct); ADC_RegularChannelConfig(ADC1,Temp_sensor_channel,1,ADC_SampleTime_56Cycles ); ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE); ADC_DMACmd(ADC1, ENABLE); ADC_Cmd(ADC1, ENABLE); ADC_TempSensorVrefintCmd(ENABLE); ADC_SoftwareStartConv(ADC1); } void Temp_Sensor_ADC_Init(void) { Temp_Sensor_ADC_Config(); } 主函数 #include "stm32f4xx.h" #include "bsp_usart.h" #include "bsp_adc.h" #define V25 0.76f #define Avg_Slope 0.0025f extern __IO uint16_t ADC_ConvertedValue; static void Delay(__IO uint32_t nCount) //简单的延时函数 { for(; nCount != 0; nCount--); } int main(void){ Usart_Config(); Temp_Sensor_ADC_Init(); while(1) { float data =(float) (ADC_ConvertedValue)/4096* (float)3.3; float temp = (data-V25)/Avg_Slope+25; printf("rn The current temp = %f C rn",temp); Delay(0xFFFFFF); } } |
|
|
|
只有小组成员才能发言,加入小组>>
3310 浏览 9 评论
2991 浏览 16 评论
3492 浏览 1 评论
9057 浏览 16 评论
4086 浏览 18 评论
1176浏览 3评论
604浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
597浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2334浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1895浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 18:26 , Processed in 0.974832 second(s), Total 49, Slave 39 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号