• 大小: 265KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-06
  • 语言: 其他
  • 标签: STM32F030  ADC  

资源简介

STM32F030使用ADC功能的例子,用定时器控制采样频率,用了DMA传输。程序注释也比较详细。其中还对比了STM32F103和STM32F030使用ADC时代码的细微区别。

资源截图

代码片段和文件信息


#include “adc.h“

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define ADC1_DR_Address                0x40012440
__IO uint16_t RegularConvData_Tab[4];
void ADC1_DMA_Init(void)
{
  ADC_InitTypeDef     ADC_InitStruct;
  DMA_InitTypeDef     DMA_InitStruct;
GPIO_InitTypeDef    GPIO_InitStruct;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimebaseInitTypeDef  TIM_TimebaseStructure;
  /* ADC1 DeInit */  
  ADC_DeInit(ADC1);

/* Enable  GPIOA clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA ENABLE);
  /* ADC1 Periph clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 ENABLE);
  /* DMA1 clock enable */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1  ENABLE);

  /* Configure PA.01  as analog input */
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOA &GPIO_InitStruct); // PA1输入时不用设置速率


    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
    GPIO_Init(GPIOA &GPIO_InitStruct);

 
  /* DMA1 Channel1 Config */
  DMA_DeInit(DMA1_Channel1);//复位DMA1_channel1
  DMA_InitStruct.DMA_PeripheralbaseAddr = (uint32_t)ADC1_DR_Address;
  DMA_InitStruct.DMA_MemorybaseAddr = (uint32_t)&RegularConvData_Tab;
  DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralSRC;//源地址为外设
  DMA_InitStruct.DMA_BufferSize =1;
  DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//外设地址寄存器不变
  DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;//内存地址寄存器递增
  DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//16位
  DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//16位
  DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;//不停传送
  DMA_InitStruct.DMA_Priority = DMA_Priority_High;
  DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;//
  DMA_Init(DMA1_Channel1 &DMA_InitStruct);
  

// DMA Transfer Complete Interrupt enable 
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;   //通道
NVIC_InitStructure.NVIC_IRQChannelPriority = 0; //占先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;           //启动
NVIC_Init(&NVIC_InitStructure);                           //初始化
 
DMA_ITConfig(DMA1_Channel1DMA_IT_TCENABLE);
DMA_ClearITPendingBit(DMA_IT_TC);  
  /* DMA1 Channel1 enable */
  DMA_Cmd(DMA1_Channel1 ENABLE);


///////////////////////////////////////////////////////////////////////
TIM_DeInit(TIM1);
//定时器1控制采样率
TIM_TimebaseStructure.TIM_Prescaler= 8-1;
TIM_TimebaseStructure.TIM_CounterMode= TIM_CounterMode_Up;
TIM_TimebaseStructure.TIM_Period= 833;
TIM_TimebaseStructure.TIM_ClockDivision= 0;
TIM_TimebaseStructure.TIM_RepetitionCounter = 0;
TIM_TimebaseInit( TIM1 &TIM_TimebaseStructure);
TIM_SelectOutputTrigger( TI

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5692  2017-08-10 17:39  drive\ADC\adc.c

     文件        113  2012-08-02 13:16  drive\ADC\adc.h

     文件       4458  2017-08-10 05:56  drive\USART\uart.c

     文件        292  2012-08-17 15:04  drive\USART\uart.h

     文件      19520  2012-04-25 11:09  lib\inc\stm32f0xx_adc.h

     文件      12353  2012-04-25 11:09  lib\inc\stm32f0xx_cec.h

     文件      10385  2012-04-25 11:09  lib\inc\stm32f0xx_comp.h

     文件       3680  2012-04-25 11:09  lib\inc\stm32f0xx_crc.h

     文件       7138  2012-04-25 11:09  lib\inc\stm32f0xx_dac.h

     文件       3892  2012-04-25 11:09  lib\inc\stm32f0xx_dbgmcu.h

     文件      14207  2012-04-25 11:09  lib\inc\stm32f0xx_dma.h

     文件       8617  2012-04-25 11:09  lib\inc\stm32f0xx_exti.h

     文件      10957  2012-04-25 11:09  lib\inc\stm32f0xx_flash.h

     文件      13174  2012-04-25 11:09  lib\inc\stm32f0xx_gpio.h

     文件      18136  2012-04-25 11:09  lib\inc\stm32f0xx_i2c.h

     文件       4531  2012-04-25 11:09  lib\inc\stm32f0xx_iwdg.h

     文件       4413  2012-04-25 11:09  lib\inc\stm32f0xx_misc.h

     文件       5909  2012-04-25 11:09  lib\inc\stm32f0xx_pwr.h

     文件      20615  2012-04-25 11:09  lib\inc\stm32f0xx_rcc.h

     文件      35039  2012-04-25 11:09  lib\inc\stm32f0xx_rtc.h

     文件      22351  2012-04-25 11:09  lib\inc\stm32f0xx_spi.h

     文件       9166  2012-04-25 11:09  lib\inc\stm32f0xx_syscfg.h

     文件      51670  2012-04-25 11:09  lib\inc\stm32f0xx_tim.h

     文件      25538  2012-04-25 11:09  lib\inc\stm32f0xx_usart.h

     文件       3537  2012-04-25 11:09  lib\inc\stm32f0xx_wwdg.h

     文件      45762  2012-08-01 14:51  lib\src\stm32f0xx_adc.c

     文件      24186  2012-04-25 11:09  lib\src\stm32f0xx_cec.c

     文件      15551  2012-04-25 11:09  lib\src\stm32f0xx_comp.c

     文件       8694  2012-04-25 11:09  lib\src\stm32f0xx_crc.c

     文件      18920  2012-04-25 11:09  lib\src\stm32f0xx_dac.c

............此处省略43个文件信息

评论

共有 条评论