你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32F407 ADC 用定时器触发DMA传送问题

[复制链接]
白开水011 提问时间:2013-7-3 08:16 /
#define ADC_CDR_ADDRESS    ((uint32_t)0x40012308)
#define ADC_Buffer_Size     1024
__IO uint32_t ADC_Buffer[ADC_Buffer_Size];


void ADC_init(void)
{
ADC_InitTypeDef       ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
DMA_InitTypeDef       DMA_InitStructure;
GPIO_InitTypeDef      GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;

/* Enable peripheral clocks */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOC |RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 |
RCC_APB2Periph_ADC3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

/* Time base configuration */
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 4512;         
TIM_TimeBaseStructure.TIM_Prescaler = 0x4;      
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;   
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

/* TIM1 channel1 configuration in PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;               
TIM_OCInitStructure.TIM_Pulse = 0x7F;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;         
TIM_OC1Init(TIM1, &TIM_OCInitStructure);

TIM_ARRPreloadConfig(TIM1, ENABLE);
TIM_OC1PreloadConfig (TIM1, TIM_OCPreload_Enable);
//TIM1->CR2 =0x00;
//TIM1->SMCR = 0x00;
//TIM1->DIER = 0x00;

/* Configure ADC Channel 12 pin as analog input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure ADC Channel 12 pin as analog input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure);

/* DMA2 Stream0 channel0 configuration */
DMA_InitStructure.DMA_Channel = DMA_Channel_0;  
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC_CDR_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = ADC_Buffer_Size;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.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_InitStructure);

/* Enable the DMA7 Interrupt*/   
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

/* DMA2_Stream0 enable */
DMA_ClearITPendingBit(DMA2_Stream0,DMA_IT_TC);
DMA_ITConfig(DMA2_Stream0,DMA_IT_TC,ENABLE);
DMA_Cmd(DMA2_Stream0, ENABLE);

/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/******************************************************************************/
/*  ADCs configuration: triple interleaved with 5cycles delay to reach 6Msps  */
/******************************************************************************/

/* ADC Common configuration *************************************************/
ADC_CommonInitStructure.ADC_Mode = ADC_TripleMode_RegSimult;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_2;  
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInit(&ADC_CommonInitStructure);

/* ADC1 regular channel 12 configuration ************************************/
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 3;
ADC_Init(ADC1, &ADC_InitStructure);

ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 1, ADC_SampleTime_15Cycles);
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 2, ADC_SampleTime_15Cycles);
ADC_RegularChannelConfig(ADC1, ADC_Channel_6,  3, ADC_SampleTime_15Cycles);

/* ADC2 regular channel 12 configuration ************************************/
ADC_Init(ADC2, &ADC_InitStructure);
/* ADC2 regular channel12 configuration */
ADC_RegularChannelConfig(ADC2, ADC_Channel_11, 1, ADC_SampleTime_15Cycles);
ADC_RegularChannelConfig(ADC2, ADC_Channel_13, 2, ADC_SampleTime_15Cycles);
ADC_RegularChannelConfig(ADC2, ADC_Channel_7,  3, ADC_SampleTime_15Cycles);

/* ADC3 regular channel 12 configuration ************************************/
ADC_Init(ADC3, &ADC_InitStructure);
/* ADC3 regular channel12 configuration */
ADC_RegularChannelConfig(ADC3, ADC_Channel_10, 1, ADC_SampleTime_15Cycles);
ADC_RegularChannelConfig(ADC3, ADC_Channel_12, 2, ADC_SampleTime_15Cycles);
ADC_RegularChannelConfig(ADC3, ADC_Channel_13, 3, ADC_SampleTime_15Cycles);

/* Enable DMA request after last transfer (multi-ADC mode) ******************/
ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE);

/* Enable ADC1 **************************************************************/
ADC_Cmd(ADC1, ENABLE);

/* Enable ADC2 **************************************************************/
ADC_Cmd(ADC2, ENABLE);

/* Enable ADC3 **************************************************************/
ADC_Cmd(ADC3, ENABLE);

/* TIM1 counter enable */
TIM_Cmd(TIM1,ENABLE);
/* TIM1 main Output Enable */
TIM_CtrlPWMOutputs(TIM1,ENABLE);
}

程序运行时,DMA中断只开始运行时发生一次,就在没有了,不知那设置错了,请各位指教!

adc.txt

下载

6.3 KB, 下载次数: 169, 下载积分: ST金币 -1

收藏 评论10 发布时间:2013-7-3 08:16

举报

10个回答
白开水011 回答时间:2013-7-3 10:46:31

RE:STM32F407 ADC 用定时器触发DMA传送问题

香版主,看看能否帮忙?
白开水011 回答时间:2013-7-3 16:41:23

RE:STM32F407 ADC 用定时器触发DMA传送问题

问题解决
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_2;
zykzyk-93033 回答时间:2013-7-3 21:07:36

RE:STM32F407 ADC 用定时器触发DMA传送问题

支持
王zheng 回答时间:2013-7-23 20:24:22

RE:STM32F407 ADC 用定时器触发DMA传送问题

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "SysTick\\systick.h"
#include
#include "USART\\usart.h"
/* Private define ------------------------------------------------------------*/
#define ADC1_DR_Address    ((u32)0x4001244C)
#define  N   100               //每通道采100次
#define  M 6               //为2个通道
/* Private function prototypes -----------------------------------------------*/
void USART_Configuration(void);
void ADC_Configuration(void);
void filter(void);
u16 GetVolt(u16 advalue) ;
/* Private variables ---------------------------------------------------------*/
vu16 ADC_ConvertedValue;
vu16  AD_Value[N][M];   //用来存放ADC转换结果,也是DMA的目标地址
vu16  After_filter[M];    //用来存放求平均值之后的结果
int  i;
int main(void)
{
        u16 value[M];
        Delay_Init();
        USART_Configuration();
        ADC_Configuration();
       
  printf("\r\n****************************************************************\r\n");
  /* Infinite loop */
  while (1)
  {
                    
                filter();  
                for(i=0;i
pchf005-126481 回答时间:2014-4-24 12:42:12

回复:STM32F407 ADC 用定时器触发DMA传送问题

谢谢
单片机爱好者 回答时间:2014-4-25 10:27:43

RE:STM32F407 ADC 用定时器触发DMA传送问题

没用过407,能不能赚1分~~
kepter 回答时间:2015-10-13 14:36:16
遇到了同样的问题   请问楼主怎么解决的啊
无线传感器啊 回答时间:2015-10-19 13:00:51
tabujianle 回答时间:2016-6-17 22:20:33
可能是DMA中断服务函数配置有问题或者采集过程中发生OVR溢出错误,如果是前者:
//ADC1的DMA数据流中断服务函数
void DMA2_Stream0_IRQHandler(void)
{
        u16 i;

       
        if(DMA_GetFlagStatus(DMA_STREAMx_ADC1 ,DMA_FLAG_TCIF0)!=RESET)
        {
                ADC_DMARequestAfterLastTransferCmd(ADC1x , DISABLE);
                ADC_DMACmd(ADC1x , DISABLE);
               
                DMA_Cmd(DMA_STREAMx_ADC1, DISABLE);
                while (DMA_GetCmdStatus(DMA_STREAMx_ADC1) != DISABLE){}//等待DMA可配
               
                       
                        for(i=0; i<ADC1_DataNum; i++)
                {               
                        uwADC1xConvertedVoltage[i] = uhADC1xConvertedValue[i] * 3300/0xFFF;               
                        printf("\r\n通道ADC_Channel_1 采样电压为 ::");
                        USART_ShowxNum(uwADC1xConvertedVoltage[i], 4);       
                }
                printf("\r\n-------------------");                       
       
                       
                ADC1DataProcess_Amp(uhADC1xConvertedValue, PGA1_GAIN);
               
                DMA_ClearFlag(DMA_STREAMx_ADC1,DMA_FLAG_TCIF0);
                DMA_SetCurrDataCounter(DMA_STREAMx_ADC1,ADC1_DataNum);//数据传输量
                DMA_Cmd(DMA_STREAMx_ADC1, ENABLE);
               
                ADC_DMARequestAfterLastTransferCmd(ADC1x , ENABLE);
                ADC_DMACmd(ADC1x , ENABLE);
        }
}

如果是后者,需要在检测到溢出后,再次从溢出状态恢复,恢复过程看数据手册有关OVR部分内容。
jorry 回答时间:2016-8-28 19:42:06
mark!!!!!!
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32Cube扩展软件包
意法半导体边缘AI套件
ST - 理想汽车豪华SUV案例
ST意法半导体智能家居案例
STM32 ARM Cortex 32位微控制器
关注我们
st-img 微信公众号
st-img 手机版