stm32f4xx adc使用心得

上传人:子 文档编号:43015327 上传时间:2018-06-04 格式:DOC 页数:9 大小:16.09KB
返回 下载 相关 举报
stm32f4xx adc使用心得_第1页
第1页 / 共9页
stm32f4xx adc使用心得_第2页
第2页 / 共9页
stm32f4xx adc使用心得_第3页
第3页 / 共9页
stm32f4xx adc使用心得_第4页
第4页 / 共9页
stm32f4xx adc使用心得_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《stm32f4xx adc使用心得》由会员分享,可在线阅读,更多相关《stm32f4xx adc使用心得(9页珍藏版)》请在金锄头文库上搜索。

1、STM32F4xxSTM32F4xx ADCADC 使用心得使用心得STM32F4xx ADC 使用心得使用心得 STM32F4 与 STM32F1 在 ADC 方面的区别 通常在 STM32F1 中需要加自动校准的程序如下 / 使能 ADC1 自动校准功能ADC_ResetCalibration(ADC1);/检查 ADC1 自校准的状态位while(ADC_GetResetCalibrationStatus(ADC1);/启动 ADC1 自校准 ADC_StartCalibration(ADC1);/检查 ADC1 自校准是否结束while(ADC_GetCalibrationStatus

2、(ADC1);/ ADC 自动校准结束-然而STM32F4 中无需此程序给出 STM32F407 的 ADC3 和 DMA 方式的官方程序如下 /* file ADC3_DMA/main.c* author MCD Application Team* version V1.0.0* date 19-September-2011* brief Main program body* attention* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS* WITH CODING INFORMATI

3、ON REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE* CODING INFORMATION C

4、ONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.* COPYRIGHT 2011 STMicroelectronics*/* Includes -*/#include “stm32f4_discovery.h“ #include /* addtogroup STM32F4_Discovery_Peripheral_Examples* */* addtogroup ADC_ADC3_DMA* */* Private typedef -*/* Private define -*/#define ADC3_DR_ADDRESS(uint32_t)0

5、x4001224C)/ADC 转换后存储内存地/址具体在 datasheet 中查阅 /* Private macro -*/* Private variables -*/* You can monitor the converted value by adding the variable “ADC3ConvertedValue“to the debugger watch window */ _IO uint16_t ADC3ConvertedValue= 0 ;/转换的结果由于此例程是 12 的/ADC转换结果在 00X0FFF 之间 _IO uint32_t ADC3ConvertedV

6、oltage = 0;/* Private function prototypes -*/* Private functions -*/void ADC3_CH12_DMA_Config(void);/* brief Main program* param None* retval None*/int main(void) /*! At this stage the microcontroller clock setting is already configured,this is done through SystemInit() function which is called from

7、 startupfile (startup_stm32f4xx.s) before to branch to application main.To reconfigure the default setting of SystemInit() function, refer tosystem_stm32f4xx.c file*/* ADC3 configuration */* - Enable peripheral clocks */* - DMA2_Stream0 channel2 configuration */* - Configure ADC Channel12 pin as ana

8、log input */* - Configure ADC3 Channel12 */ADC3_CH12_DMA_Config();/* Start ADC3 Software Conversion */ADC_SoftwareStartConv(ADC3);ADC3_CH12_DMA_Config();/* Start ADC3 Software Conversion */ADC_SoftwareStartConv(ADC3);/软件启动转换因此 ADC 初始化时设置成/ADC_ExternalTrigConvEdge_None;while (1)/* convert the ADC val

9、ue (from 0 to 0xFFF) to a voltage value (from 0V to 3.3V)*/ADC3ConvertedVoltage = ADC3ConvertedValue *3300/0xFFF;/* brief ADC3 channel12 with DMA configuration* param None* retval None*/void ADC3_CH12_DMA_Config(void)ADC_InitTypeDefADC_InitStructure;ADC_CommonInitTypeDef ADC_CommonInitStructure;DMA_

10、InitTypeDefDMA_InitStructure;GPIO_InitTypeDefGPIO_InitStructure;/* Enable ADC3, DMA2 and GPIO clocks */RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOC, ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);/* DMA2 Stream0 channel0 configuration */DMA_InitStructure.DMA_Channel

11、 = DMA_Channel_2;DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC3_DR_ADDRESS;DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; /设置 DMA 方向为外设/到内存DMA_InitStructure.DMA_BufferSize = 1;/多通道采样时需要修改DMA_InitStructure.DMA_PeripheralInc = DMA_P

12、eripheralInc_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_InitStruc

13、ture.DMA_Priority = DMA_Priority_High;DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;DMA_Init(DMA2_Stream0, DMA_Cmd(DMA2_Stream0, ENABLE);/* Configure ADC3 Channel12

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号