资源简介
STM32F3系列,采用ADC采样外部电位器的输入电压,将转换结果使用DMA模式传输,并对每8次采样去平均值做滤波处理
代码片段和文件信息
/**
******************************************************************************
* @file : ADC_DMA.c
* @author : wind
* @version:
* @date :20150508
* @brief :
******************************************************************************
*/
/* ---------------------------------------------------------------------------*/
#include “ADC_DMA.h“
#define DATANUM 8
uint8_t FLAG = 0; //转换次数标志位
uint16_t CONV_RESULTS[DATANUM];
void ADC_Config(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div2);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12ENABLE);
GPIO_Config();
ADC_StructInit(&ADC_InitStructure);
ADC_VoltageRegulatorCmd(USING_ADC ENABLE);
delay_us(10);
ADC_SelectCalibrationMode(USING_ADC ADC_CalibrationMode_Single);
ADC_StartCalibration(USING_ADC);
while(ADC_GetCalibrationStatus(USING_ADC) != RESET );
//Common Init
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_2;
ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_Circular;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = 0;
ADC_CommonInit(USING_ADC&ADC_CommonInitStructure);
//ADC Init
ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Disable;
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_9;
ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_BothEdge;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;
ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable;
ADC_InitStructure.ADC_NbrOfRegChannel = 1;
ADC_Init(USING_ADC&ADC_InitStructure);
ADC_RegularChannelConfig(USING_ADC ADC_CHANNEL 1 ADC_SampleTime_181Cycles5);
//ADC_ExternalTriggerConfig(USING_ADC ADC_ExternalTrigConvEvent_9 ADC_ExternalTrigEventEdge_BothEdge);
ADC_ITConfig(USING_ADC ADC_IT_EOC ENABLE);
ADC_DMAConfig(USING_ADC ADC_DMAMode_Circular);
ADC_DMACmd(USING_ADC ENABLE);
DMA_Config();
ADC_Cmd(USING_ADCENABLE);
while(!ADC_GetFlagStatus(USING_ADC ADC_FLAG_RDY));
ADC_StartConversion(USING_ADC);
}
void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(ADC_PORT_CLKENABLE);
GPIO_InitStructure.GPIO_Pin = ADC_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(ADC_PORT&GPIO_InitStructure);
}
void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 ENABLE);
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralbaseAddr = ADC_DATA_ADDR;
DMA_InitStructure.DMA_Me
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4199 2015-05-08 00:59 ADC_DMA.c
文件 903 2015-05-08 00:38 ADC_DMA.h
----------- --------- ---------- ----- ----
5102 2
评论
共有 条评论