AnsweredAssumed Answered

ADC triple Injected mode in stm32f4discovery

Question asked by slimsly on Oct 8, 2015
Latest reply on Oct 8, 2015 by slimsly
Hello,
 
I have been trying for days to get the ADC in STm32f4Discovery board to work in triple regular Injected simultaneous mode with no luck. My intended goal is setup the ADC to work in triple Injected simultaneous mode + Regular simultaneous mode. I have successfully implemented the Triple Regular simultaneous mode with the values read from DMA (Trigger by TIM3_CC1). I want to the trigger the ADC with TIM8_CC4 falling edge. I setup interrupt at the end of injected adc conversion. The interrupt do trigger but I can’t get any values from neither ADC1,2 or 3 injected register. I changed the ADC pin from PORT A to PORT C but can’t get any values. I have search the forum for any cases of in triple Injected simultaneous mode but nothing was found. I will be glad if someone point to the right direction.


#include "stm32f4xx.h"
void ADC123_Config(void);
void ADC1_CH5_CH6_InjConfig(void);
void ADC2_CH2_CH3_InjConfig(void);
void ADC3_CH0_CH1_InjConfig(void);
 
void ADC123_Config(void)
{
  ADC_CommonInitTypeDef ADC_CommonInitStructure;          
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);            
  ADC_CommonInitStructure.ADC_Mode = ADC_TripleMode_InjecSimult;
  ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;
  ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
  ADC_CommonInit(&ADC_CommonInitStructure);         
}

void ADC1_CH5_CH6_InjConfig(void)
{
  ADC_InitTypeDef ADC_InitStructure;               
  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_Init(ADC1, &ADC_InitStructure);
     
  /* Injected channels for Configuration **************************************/
ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_T8_CC4);
 ADC_ExternalTrigInjectedConvEdgeConfig(ADC1, ADC_ExternalTrigInjecConvEdge_Falling);
 ADC_AutoInjectedConvCmd(ADC1, DISABLE);                
 ADC_InjectedDiscModeCmd(ADC1, DISABLE);
 ADC_InjectedSequencerLengthConfig(ADC1, 2);
 ADC_InjectedChannelConfig(ADC1, ADC_Channel_5, 1, ADC_SampleTime_15Cycles);
 ADC_InjectedChannelConfig(ADC1, ADC_Channel_6, 2, ADC_SampleTime_15Cycles);

  /* Enable ADC Regular & Injected Channel complete interrupt *****************/
 ADC_ITConfig(ADC1, ADC_IT_JEOC, ENABLE);   
}


void ADC2_CH2_CH3_InjConfig(void)
{
  ADC_InitTypeDef ADC_InitStructure;
  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_Init(ADC2, &ADC_InitStructure);

  /* Injected channels for Configuration **************************************/
  ADC_ExternalTrigInjectedConvConfig(ADC2, ADC_ExternalTrigInjecConv_T8_CC4);
  ADC_ExternalTrigInjectedConvEdgeConfig(ADC1, ADC_ExternalTrigInjecConvEdge_None);
  ADC_AutoInjectedConvCmd(ADC2, DISABLE);                
  ADC_InjectedDiscModeCmd(ADC2, DISABLE);
  ADC_InjectedSequencerLengthConfig(ADC2, 2);
  ADC_InjectedChannelConfig(ADC2, ADC_Channel_2, 1, ADC_SampleTime_15Cycles);
  ADC_InjectedChannelConfig(ADC2, ADC_Channel_3, 2, ADC_SampleTime_15Cycles);
}

void ADC3_CH0_CH1_InjConfig(void)
{
  ADC_InitTypeDef ADC_InitStructure;
  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_Init(ADC3, &ADC_InitStructure);         

 /* Injected channels for Configuration **************************************/
 ADC_ExternalTrigInjectedConvConfig(ADC3, ADC_ExternalTrigInjecConv_T8_CC4);
 ADC_ExternalTrigInjectedConvEdgeConfig(ADC1, ADC_ExternalTrigInjecConvEdge_None);
 ADC_AutoInjectedConvCmd(ADC3, DISABLE);                
 ADC_InjectedDiscModeCmd(ADC3, DISABLE);
 ADC_InjectedSequencerLengthConfig(ADC3, 2);
 ADC_InjectedChannelConfig(ADC3, ADC_Channel_0, 1, ADC_SampleTime_15Cycles);
 ADC_InjectedChannelConfig(ADC3, ADC_Channel_1, 2, ADC_SampleTime_15Cycles);
}

void GPIO_Config(void) {
  GPIO_InitTypeDef       GPIO_InitStructure;        
  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA , ENABLE);
  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOB , ENABLE);
  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOC , ENABLE);
  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOD , ENABLE);          
  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOE , ENABLE);

/* Configure PD12 to PED15 as output ***********************/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12  | GPIO_Pin_13  | GPIO_Pin_14 | GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  /* Configure ADC CH1(PA1), CH2(PA2), CH3(PA3) pins as analog inputs *****/
  /* Configure ADC CH4(PA4), CH5(PA5), CH6(PA6) pins as analog inputs *****/
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3  | GPIO_Pin_0 | GPIO_Pin_5 | GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
}

Outcomes