打印

ADC1_DMA例程,解释一下例程的功能

[复制链接]
1635|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
sdlcxyx|  楼主 | 2010-9-8 10:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
DMA, ADC1, ST, IO, rc
各位老师,谁能告诉我这个例程实现了什么功能呀?可修改的部分在哪儿?给我解释一下好吗?
初次接触STM32,迫切希望得到大家的帮助和支持!

#include "stm32f10x_lib.h"

#define ADC1_DR_Address    ((u32)0x4001244C)


ADC_InitTypeDef ADC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
vu16 ADCConvertedValue;
ErrorStatus HSEStartUpStatus;
   

void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
  

int main(void)
{
#ifdef DEBUG
  debug();
#endif

  RCC_Configuration();
  
  NVIC_Configuration();
  GPIO_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);
  
   DMA_Cmd(DMA1_Channel1, ENABLE);
     

  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_14, 1, ADC_SampleTime_55Cycles5);
  /* 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);
  while (1)
  {
  }
}

void RCC_Configuration(void)
{
  
  RCC_DeInit();
  RCC_HSEConfig(RCC_HSE_ON);
  
  HSEStartUpStatus = RCC_WaitForHSEStartUp();
  if(HSEStartUpStatus == SUCCESS)
  {

    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
  
    FLASH_SetLatency(FLASH_Latency_2);
  
   
    RCC_HCLKConfig(RCC_SYSCLK_Div1);
  
   
    RCC_PCLK2Config(RCC_HCLK_Div1);
  
    RCC_PCLK1Config(RCC_HCLK_Div2);
        RCC_ADCCLKConfig(RCC_PCLK2_Div4);
  
   
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_7);
   
    RCC_PLLCmd(ENABLE);
   
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {
    }
   
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
  
    while(RCC_GetSYSCLKSource() != 0x08)
    {
    }
  }


  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC, ENABLE);
}

void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
}

void NVIC_Configuration(void)
{
#ifdef  VECT_TAB_RAM  
  /* Set the Vector Table base location at 0x20000000 */
  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else  /* VECT_TAB_FLASH  */
  /* Set the Vector Table base location at 0x08000000 */
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   
#endif
}
#ifdef  DEBUG

void assert_failed(u8* file, u32 line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* Infinite loop */
  while (1)
  {
  }
}
#endif

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

14

帖子

1

粉丝