AnsweredAssumed Answered

STM32F30x ADC dual regular simult. mode, 8 bit

Question asked by ostrowski.tomasz.002 on Jun 1, 2013
Latest reply on Jun 16, 2013 by ostrowski.tomasz.002
Hello,
I'm trying to run STM32F30x ADC in dual regular simultaneous 8-bit mode and I would like to ask for help. My MCU is STM32F303CBT6, rev. Y, I'm using ADC 1+2 for PA0 and PA4 sampling respectively.
Unfortunately I'm must be missing something because I'm getting samples only from first (PA0) channel (or from PA4 if ADC_RegularChannelConfig calls order is reversed). Samples from second channel are equal to zero.
Here is my ADC/DMA initialization:
enum { ADC_HALF_BUFFER = 512 };
unsigned int ADCbuf[2*ADC_HALF_BUFFER];
 
 
static void setup_adc_gpio(void)
{
    GPIO_InitTypeDef       GPIO_InitStructure;
    /* Enable GPIOA Periph clock */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
 
    /* Configure ADC1/2 channels as analog input */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_4;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
}
 
static void setup_adc_dma(void)
{
    DMA_InitTypeDef        DMA_InitStructure;
    /* Enable DMA1 clock */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
 
    /* DMA1 Channel1 Init */
    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1_2->CDR;
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; 
    DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADCbuf;
    DMA_InitStructure.DMA_BufferSize = sizeof(ADCbuf)/sizeof(ADCbuf[0]);
    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_Medium;
    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
 
    DMA_Init(DMA1_Channel1, &DMA_InitStructure);
 
    /* DMA interrupts */
    DMA_ITConfig(DMA1_Channel1, DMA_IT_TC | DMA_IT_HT, ENABLE);
 
    /* enable DMA IRQ */
    NVIC_EnableIRQ(DMA1_Channel1_IRQn);
}
 
static void calibrate_adc(void)
{
    __IO uint16_t calibration_value_1 = 0;  ///< __IO = volatile   
    __IO uint16_t calibration_value_2 = 0; 
 
  /* ADC Calibration procedure */
  ADC_VoltageRegulatorCmd(ADC1, ENABLE);
  ADC_VoltageRegulatorCmd(ADC2, ENABLE);
   
  /* Insert delay equal to 10 µs */
  SystickDelay(10);
   
  ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single);
  ADC_StartCalibration(ADC1);
 
  ADC_SelectCalibrationMode(ADC2, ADC_CalibrationMode_Single);
  ADC_StartCalibration(ADC2);
   
  while(ADC_GetCalibrationStatus(ADC1) != RESET );
  calibration_value_1 = ADC_GetCalibrationValue(ADC1);
 
  while(ADC_GetCalibrationStatus(ADC2) != RESET );
  calibration_value_2 = ADC_GetCalibrationValue(ADC2); 
}
 
void setup_adc(adc_data_cb on_adc_data)
{
    ADC_CommonInitTypeDef    ADC_CommonInitStructure;
    ADC_InitTypeDef        ADC_InitStructure;
         
    adc_data_callback = on_adc_data;
 
    /* Configure the ADC clock */
    RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div64); 
    /* Enable ADC1 clock */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);
         
    setup_adc_gpio();
    setup_adc_dma();
     
  /* Setup SysTick Timer for 1 µsec interrupts  */
  if (SysTick_Config(SystemCoreClock / 1000000))
  {
    Buzzer_On();
        /* Capture error */
    while (1)
    {}
  }
   
    calibrate_adc();
 
    ADC_CommonStructInit(&ADC_CommonInitStructure);
    ADC_CommonInitStructure.ADC_Mode = ADC_Mode_RegSimul;
    ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode; //ADC_Clock_SynClkModeDiv1
    ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1 ; // ADC_DMAAccessMode_2
    ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_Circular;
    ADC_CommonInitStructure.ADC_TwoSamplingDelay = 0;
    ADC_CommonInit(ADC1, &ADC_CommonInitStructure);
 
    /* ADC setup */ 
    ADC_StructInit(&ADC_InitStructure);
    ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable;
    ADC_InitStructure.ADC_Resolution = ADC_Resolution_8b;
    ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;        
    ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;
    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
    ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;  
    ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable; 
    ADC_InitStructure.ADC_NbrOfRegChannel = 1;
    ADC_Init(ADC1, &ADC_InitStructure);
    ADC_Init(ADC2, &ADC_InitStructure);
 
  ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_7Cycles5);
  ADC_RegularChannelConfig(ADC2, ADC_Channel_5, 1, ADC_SampleTime_7Cycles5);   
     
    /* Configures the ADC DMA */
    ADC_DMAConfig(ADC1, ADC_DMAMode_Circular);
         
    /* Enable the ADC DMA */
    ADC_DMACmd(ADC1, ENABLE);
 
  /* Enable ADC1 and ADC2 */
  ADC_Cmd(ADC1, ENABLE);
  ADC_Cmd(ADC2, ENABLE);
 
    /* wait for ADC1 ADRDY */
    while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY));
     
  /* wait for ADC2 ADRDY */
  while(!ADC_GetFlagStatus(ADC2, ADC_FLAG_RDY));   
 
    /* Enable the DMA channel */
    DMA_Cmd(DMA1_Channel1, ENABLE);
 
    /* Start ADC1 Software Conversion */
    ADC_StartConversion(ADC1);
}

Whole Keil project (packed with 7-zip) - kind of basic USB oscilloscope:
miniscope_v2d_20130601.7z

Outcomes