/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / MultiChannel ADC Scan returns all 0s

Username:     
Password:     
             

Forum

# 1   2011-04-06 09:19:50 MultiChannel ADC Scan returns all 0s

saiRam
Member
Registered: 2011-03-21
Posts: 18

MultiChannel ADC Scan returns all 0s

Hi, I am using 6 ADC channels ADC_Channel_15,ADC_Channel_14,ADC_Channel_13,ADC_Channel_11, ADC_Channel_4,ADC_Channel_6 of STM32F107VCT6 MCU to connect to 6 devices.
I use mutichannel continuous conversion mode of ADC sampling. I enable EOC(End Of Conversion) interrupt so that i get an interrupt after a cycle of conversion is done.
I use DMA to save the converted data. When I read back the data after an interrupt is triggered, I am all getting zeros. When I instead use a polling method where I
just go and poll the channels, I could read valid data. Can any one help me with this?

/*external Variables --------------------------------------*/
  uint16_t ADC_ConvertedValue[6];
  b00l flag

/* Private variables ---------------------------------------------------------*/
  ADC_InitTypeDef ADC_InitStructure;
  DMA_InitTypeDef DMA_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;

 
/* Enable GPIO clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC  | RCC_APB2Periph_AFIO , ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA  | RCC_APB2Periph_AFIO , ENABLE);

  /* PCLK2 is the APB2 clock */
   /* ADCCLK = PCLK2/6 = 72/6 = 12MHz - ADCCLK should be less than 14MHz*/
   RCC_ADCCLKConfig(RCC_PCLK2_Div6);

   /* Enable ADC1 clock so that we can talk to it */
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

    /* Configure GPIO pins to have photo sensors connected to ADC channels */
   GPIO_InitStructure.GPIO_Pin = R_PS_ID0_PIN | R_PS_ID1_PIN | R_PS_ID2_PIN | R_PS_ID3_PIN;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
   GPIO_Init(R_PS_ADC_GPIO_PORT_C, &GPIO_InitStructure);

   GPIO_InitStructure.GPIO_Pin = R_PS_ID4_PIN | R_PS_ID5_PIN;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
   GPIO_Init(R_PS_ADC_GPIO_PORT_A, &GPIO_InitStructure);

    /* Disable the alternative GPIO pins so that ADC channel will be active */

    GPIO_WriteBit(R_PS_ADC_GPIO_PORT_C, R_PS_ID0_PIN, Bit_RESET);
   GPIO_WriteBit(R_PS_ADC_GPIO_PORT_C, R_PS_ID1_PIN, Bit_RESET);
   GPIO_WriteBit(R_PS_ADC_GPIO_PORT_C, R_PS_ID2_PIN, Bit_RESET);
   GPIO_WriteBit(R_PS_ADC_GPIO_PORT_C, R_PS_ID3_PIN, Bit_RESET);
   GPIO_WriteBit(R_PS_ADC_GPIO_PORT_A, R_PS_ID4_PIN, Bit_RESET);
   GPIO_WriteBit(R_PS_ADC_GPIO_PORT_A, R_PS_ID5_PIN, Bit_RESET);

  /* DMA Channel1 Configuration ----------------------------------------------*/
   DMA_DeInit(DMA1_Channel1);
  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR;
  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) &ADC_ConvertedValue;
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
  DMA_InitStructure.DMA_BufferSize = 6;
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  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);

  /* Enable DMA Channel1 */
  DMA_Cmd(DMA1_Channel1, ENABLE);


/* ADCx Configuration (ADC1CLK = 12 MHz) -----------------------------------*/
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 = 6;
ADC_Init(ADC1, &ADC_InitStructure);


/* ADCx Regular Channel Configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 1, ADC_SampleTime_1Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 2, ADC_SampleTime_7Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 3, ADC_SampleTime_13Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 4, ADC_SampleTime_28Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 5, ADC_SampleTime_41Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 6, ADC_SampleTime_55Cycles5);

 
/* Enable ADCx's DMA interface */
ADC_DMACmd(ADC1, ENABLE);

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

ADC_ITConfig(ADC1,ADC_IT_EOC,ENABLE);     
My_ADC_IT_Config();


/* Start ADC1 Software Conversion */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);


  while (1)
  {
      if(flag == TRUE)
      {
        printf("\r\n%d,%d,%d,%d,%d,%d\n",ADC_ConvertedValue[0],ADC_ConvertedValue[1],ADC_ConvertedValue[2],
                                       ADC_ConvertedValue[3],ADC_ConvertedValue[4],ADC_ConvertedValue[5]);
        flag = FALSE;
      }
  }

/************NVIC Configurations***************/

void R_ADC_IT_Config()
{
  NVIC_InitTypeDef NVIC_InitStructure;

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

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


void ADC1_2_IRQHandler(void)
{   
    flag = TRUE; 
    ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);
}

Offline

 

# 2   2011-04-07 06:56:04 MultiChannel ADC Scan returns all 0s

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: MultiChannel ADC Scan returns all 0s

I think you forgot to clock the DMA before configuring it :
    RCC_AHBPeriphClockCmd( RCC_AHBPeriph_DMA1, ENABLE );

I don't understand why you configure your GPIO in AF_PP and you $1 ? The right way to configure ADC channels is : $1
What was the idea ?

Offline

 

Board footer