AnsweredAssumed Answered

DMA1_Channel1_IRQHandler

Question asked by netto.moraes on Aug 28, 2013
Latest reply on Dec 8, 2015 by Clive One
Hi.
I need to read three analog inputs and perform the average of 20 measurements of both values, and can not waste time processing the average of these values. For this I am using the code below. The reading of the analog inputs is correct, but I'm not getting read interruptions DMA1_Channel1. My goal is to calculate the mean of the values read from the analog channels each interruption Channel 1 DMA1.

If anyone can help me, I'm grateful.

Code:
/*---------------------------------------------------------------------------------
  CONFIGURATION CLOCK
----------------------------------------------------------------------------------*/
void RCC_Configuration(void)
{
     /* DMA clock enable */
     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 | RCC_AHBPeriph_DMA2, ENABLE);


     /* Enable ADC1, ADC2, ADC3 and GPIOC clocks */
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 | RCC_APB2Periph_ADC3 | RCC_APB2Periph_GPIOC, ENABLE);


     /* ADC 1 clocks */
     RCC_ADCCLKConfig(RCC_PCLK2_Div6);
     RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO | RCC_APB2Periph_ADC1, ENABLE);
}
/*--------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------
  CONFIGURATION GPIO
----------------------------------------------------------------------------------*/
void GPIO_Configuration(void)
{
     GPIO_InitTypeDef GPIO_InitStructure;

     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_Init(GPIOC, &GPIO_InitStructure);

     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_Init(GPIOC, &GPIO_InitStructure);
     
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_Init(GPIOC, &GPIO_InitStructure);                                        
}
/*--------------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------------
  CONFIGURATION - DMA
----------------------------------------------------------------------------------*/
void AD_DMA_Configuration(void)
{
     DMA_InitTypeDef DMA_InitStructure;
     ADC_InitTypeDef ADC_InitStructure;
     NVIC_InitTypeDef NVIC_InitStructure;

     NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

     /* Configure and enable ADC interrupt */
     NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQChannel;
     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
     NVIC_Init(&NVIC_InitStructure);

     NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQChannel;
     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
     NVIC_Init(&NVIC_InitStructure);

      /* DMA1 Channel Config */
     /* CONFIGURAÇÃO PARA MEDIÇÃO CORRENTE E TENSÃO DE CAMPO */
     DMA_InitStructure.DMA_BufferSize = 3;
     DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
     DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
     DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADCBuffer;
     DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
     DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
     DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
     DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&ADC1->DR;
     DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
     DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
     DMA_InitStructure.DMA_Priority = DMA_Priority_High;
     DMA_Init(DMA1_Channel1, &DMA_InitStructure);
     DMA_Cmd(DMA1_Channel1, ENABLE);
 
     ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
     ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
     ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
     ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
     ADC_InitStructure.ADC_NbrOfChannel = 3;
     ADC_InitStructure.ADC_ScanConvMode = ENABLE;
     ADC_Init(ADC1, &ADC_InitStructure);

     ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_28Cycles5);
     ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 2, ADC_SampleTime_28Cycles5); 
     ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 3, ADC_SampleTime_28Cycles5);

     ADC_Cmd(ADC1, ENABLE);
     ADC_DMACmd(ADC1, ENABLE);

     ADC_ResetCalibration(ADC1);
     while(ADC_GetResetCalibrationStatus(ADC1));
     ADC_StartCalibration(ADC1);
     while(ADC_GetCalibrationStatus(ADC1));
     ADC_SoftwareStartConvCmd(ADC1, ENABLE);

     DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
     //ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
     //ADC_ITConfig(ADC1, ADC_IT_JEOC, ENABLE);
     //ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);     
}

void DMA1_Channel1_IRQHandler(void)
{
  if(DMA_GetITStatus(DMA1_IT_TC1))
  {
     // My functions ...
     DMA_ClearITPendingBit(DMA1_IT_GL1);
  }
}




Outcomes