0
\$\begingroup\$

I have 7 adc channel must be measured. 4 channels are continuously measured by dma and adc 1, 3 of them are very important measured in special moment. I want to mesured this channels by injected channel adc2. my code for this as follow, but I can not mesured injected channels in adc2 and regular channels in adc1

configuration of GPIO as follow:

void ADC1_GPIO_Config(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;    
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);   
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);   

    // GPIO Init for regular channels
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_0|GPIO_Pin_1;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;         
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_3|GPIO_Pin_4;
  GPIO_Init(GPIOC, &GPIO_InitStructure);


    // GPIO Init for injected channels
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2;
   GPIO_Init(GPIOC, &GPIO_InitStructure);
}

and configuration of DMA is:

void DMA1_Mode_Config(void)
{
    DMA_InitTypeDef DMA_InitStructure;


    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

    /* DMA channel1 configuration */
    DMA_DeInit(DMA1_Channel1);
    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
    DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
    DMA_InitStructure.DMA_Priority = DMA_Priority_High;
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; 
    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;  
    DMA_InitStructure.DMA_BufferSize = 4;
    DMA_InitStructure.DMA_PeripheralBaseAddr =  (uint32_t)&ADC1->DR;;
    DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) &ADC_ConvertedValue;
    DMA_Init(DMA1_Channel1, &DMA_InitStructure);

    DMA_Cmd(DMA1_Channel1, ENABLE);
}

configuration of ADC1 is:

void ADC1_Mode_Config(void)
{

  ADC_InitTypeDef ADC_InitStructure;    
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
  ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;                                        
  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 = 7;                                                               
  ADC_Init(ADC1, &ADC_InitStructure);                                                                       

  ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_1Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 2, ADC_SampleTime_1Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_13,3, ADC_SampleTime_1Cycles5);
  ADC_RegularChannelConfig(ADC1,ADC_Channel_14, 4, ADC_SampleTime_1Cycles5);

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

  while(ADC_GetResetCalibrationStatus(ADC1));
  ADC_StartCalibration(ADC1);
  while(ADC_GetCalibrationStatus(ADC1));

  ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}

void ADC1_Init(void)
{
    ADC1_GPIO_Config();
    DMA1_Mode_Config();
    ADC1_Mode_Config();

}

and configuration of ADC2 is:

void ADC2_Init_MSS(void)
{

   ADC_InitTypeDef ADC_InitStructure;  


  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);

  /* ADC2 configuration */
  ADC_InitStructure.ADC_Mode = ADC_Mode_InjecSimult;                                      

  ADC_InitStructure.ADC_ScanConvMode = ENABLE;                                                    
  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;                                       
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;       
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;                                
  ADC_InitStructure.ADC_NbrOfChannel = 3;                                                               
  ADC_Init(ADC2, &ADC_InitStructure);                                                                       

 ADC_InjectedChannelConfig(ADC2,ADC_Channel_10,1,ADC_SampleTime_1Cycles5);      
 ADC_InjectedChannelConfig(ADC2,ADC_Channel_11,2,ADC_SampleTime_1Cycles5);       
 ADC_InjectedChannelConfig(ADC2,ADC_Channel_12,3,ADC_SampleTime_1Cycles5);
 ADC_InjectedSequencerLengthConfig(ADC2,3);
 ADC_InjectedSequencerLengthConfig(ADC2,3);

 ADC_ResetCalibration(ADC2);
 while(ADC_GetResetCalibrationStatus(ADC2));
 ADC_StartCalibration(ADC2);
 while(ADC_GetCalibrationStatus(ADC2));
 ADC_SoftwareStartConvCmd(ADC2, ENABLE); 
}
\$\endgroup\$
  • 1
    \$\begingroup\$ For the benefit of other interested readers here, today the OP has asked the same question (twice, by mistake?) at the ST Community here and here. Therefore useful replies / discussion might appear over there, instead of (or as well as) here. \$\endgroup\$ – SamGibson Jan 1 at 6:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.