首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

STM32学习笔记之DMA模式下的ADC

STM32学习笔记之DMA模式下的ADC

今天学习STM32的内部自带12位ADC,
1、特点:
(1)12位分辨率,最短时钟周期为14个,时钟周期可调,分别可以调整为14、20、26、41、54、68、252,因此当时钟为14MHz时候,最快转换时间为1us;
(2)供电电压为2.4V到3.6V,注意stm32的最低供电电压可以是2V,但是使用ADC时候,必须达到2.4V以上;
(3)输入电压范围:Vref-<vin<vref+,其中vref-=0v,vret+的范围是2.4v到3.6v;</vin<vref+,其中vref-=0v,vret+的范围是2.4v到3.6v;
(4)最小量化单位为:LSB=Vref+/4096mV;
(5)为逐次比较型AD;
2、处理AD转换的方法有两个:一个是常用的中断,另一个是DMA,相对来说,DMA模式下的效率要高,所以这里研究DMA下的ADC。
3、实验目标:通过ADC1的11通道采集外部电压,然后又DMA传送到缓存,然后通过串口发到到PC上。
4、实验程序:

#include"stm32f10x.h"
#include"adc.h"

/******************
  function name:ADC1_Init()
  discribe :ADC1初始化函数,调用配置函数和模式选择函数
  input:null
  output:null
*******************/
  void ADC1_Init(void)
  {
     ADC1_GPIO_Config();
ADC1_Mode_Config();
  }

/******************
  function name:ADC1_GPIO_Config()
  discribe :ADC1 config function
     (1)enable ADC,GPIO,DMA's clock,
(2)ADC1's IO is PC1,Mode is analog
input(AIN)

  input:null
  output:null
  return: null
*******************/
void ADC1_GPIO_Config(void)
{

}

/******************
  function name:ADC1_Mode_Config()
  discribe :ADC1  mode configuration
     (1)config DMA
(2)config ADC1
  input:null
  output:null
  return:null
*******************/
void ADC1_Mode_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
ADC_InitTypeDef ADC_InitStructure;

/*******config DMA channel 1 ********/
DMA_DeInit(DMA_Channel1);   //reset DMA channel register
//define the peripheral base address
DMA_InitStructure.DMA_PeripheralBaseAddr=ADC1_DR_Address;
//define the memory base address
DMA_InitStructure.DMA_MemoryBaseAddr=(u32)&ADC1_ConvertedValue;
//choose the peripheral is the destination or source
DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralSRC;
//set the DMA buffer size 缓存大小
DMA_InitStructure.DMA_BufferSize=1; //16bits
//set the peripheral address register is incremented or not 递增与否
DMA_InitStructure.DMA_PeripheralInc=DMA_PeripheralInc_Disable;
//set the memory address register is incremented or not
DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Disable;
//set the peripheral data size as 16bits(halfword)
DMA_InitStructure.DMA_PeripheralDataSize=DMA_PeripheralDataSize_HlafWord;
//set the memory data size
     DMA_InitStructure.DMA_MemoryDataSize=DMA_MemoryDataSize_HlafWord;
//set DMA mode
DMA_InitStructure.DMA_Mode=DMA_Mode_Circular;
//set the channel priority
DMA_InitStructure.DMA_Priority=DMA_Priority_High;
//enable the DMA memory to memory transfer
DMA_InitStructure.DMA_M2M=DMA_M2M_Disable;

DMA_Init(DMA_Channel1,&DMA_InitStructure);
/*****enable channel 1******/
DMA_Cmd(DMA_Channel1,ENABLE);

/*****independent scanmode none external ,right align,***/
ADC_InitStructure.ADC_Mode=ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode=ADC_ScanConvMode_ENABLE;


返回列表