AnsweredAssumed Answered

ADC+DMA on STM32F207ZG Board

Question asked by jeevananthan.luxsumi on Oct 7, 2014
Latest reply on Oct 9, 2014 by jeevananthan.luxsumi

I have a STM32F207ZG-SK board, and I want to configure pin B0 and A6 to read analog values from another board.

Did I do the setup for pin B0 and A6 correctly? I checked to see if it has ADC and it does, so I just changed certain areas of the code. The code was originally for Pin A0 and C5.

GPIO.B0 --> ADC12_IN8 --> ADC 1 or 2, and channel 8
GPIO.A6 --> ADC12_IN6 --> ADC 1 or 2, and channel 6

The code was originally for GPIO.A0 and GPIO.C5.
GPIO.B0 is replacing GPIO.A0 and GPIO.A6 is replacing GPIO.C5. 
I have highlighted the changes that I have made in the code below , but still the code doesn't work, and I don't know what I am missing.

The data sheet is located here

Below is the code: 

 /****** Setup and Initialization*****/
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
 
__IO Int16U Adcdata[2];
__IO float Adc1=0;
__IO float Adc2=0;
float Adc1_ref=0;
float Adc2_ref=0;
__IO uint16_t Adc1con=0;
__IO uint16_t Adc2con=0;

  ENTR_CRT_SECTION();

  if(SysTick_Config(SystemCoreClock/10000))
 {  
    while (1);
  }
  
  EXT_CRT_SECTION(); 
  
#define ADC_CCR_ADDRESS   ((uint32_t)0x40012308);


RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2| RCC_AHB1Periph_GPIO
B | RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOE, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2 |RCC_APB2Periph_ADC1 , ENABLE);
DMA_StructInit(&DMA_InitStructure); 


DMA_DeInit(DMA2_Stream0);  //Set DMA registers to default values
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC_CCR_ADDRESS; //Source address*/
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&Adcdata; //Destination address*/
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = 2; //Buffer size
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //source size - 16bit
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; // destination size = 16b
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; 
DMA_Init(DMA2_Stream0, &DMA_InitStructure); //Initialize the DMA

DMA_Cmd(DMA2_Stream0, ENABLE);


/*GPIO.
B0 Initialize*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIO
B, &GPIO_InitStructure);


/*GPIO.
A6 Initialize*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_
6;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIO
A, &GPIO_InitStructure);


/*ADC1 Common Init*/
ADC_CommonInitStructure.ADC_Mode = ADC_DualMode_RegSimult;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_6Cycles;

ADC_CommonInit(&ADC_CommonInitStructure);


/*ADC1 Initialize*/
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1; /* parallel so it is doing one conversion for one channel and one conversion for the other ADC channel*/
ADC_Init(ADC1, &ADC_InitStructure);

//ADC1 P
B0
ADC_RegularChannelConfig(ADC1, ADC_Channel_
8, 1, ADC_SampleTime_56Cycles);


/*ADC2 Common Initialization*/
ADC_CommonInitStructure.ADC_Mode = ADC_DualMode_RegSimult;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1;
ADC_CommonInit(&ADC_CommonInitStructure);

/*ADC2 Initialization*/
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1; //parallel ADC's for both channels. This is for each one

ADC_Init(ADC2, &ADC_InitStructure);

/*ADC2 regular TRIMER_CHANNEL configuration*/
ADC_RegularChannelConfig(ADC2, ADC_Channel_
6, 1, ADC_SampleTime_56Cycles);


ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE);

/* Enable ADCs */
ADC_Cmd(ADC1, ENABLE);
ADC_Cmd(ADC2, ENABLE);

/*Enable DMA for ADC1*/
ADC_DMACmd(ADC1, ENABLE);

/*Turn on Backlight*/
GLCD_Backlight(BACKLIGHT_ON);
GLCD_SetFont(&Terminal_9_12_6,0x000F00,0x00FF0);
GLCD_SetWindow(10,116,131,131);
ADC_SoftwareStartConv(ADC1);

Adc1=(((float)Adcdata[0]) * 3.3)/4096;  //read voltage value from ADC1
Adc2=(((float)Adcdata[1]) * 3.3)/4096; //read voltage value from ADC2



Outcomes