cancel
Showing results for 
Search instead for 
Did you mean: 

Multi ADC conversion

bmwael1
Associate II
Posted on January 21, 2013 at 14:53

Hi

friends

I use this program to Read ADC1 Value connected to PC2 port

of my

''stm32f4discovery'' card

.

/****************************************************************************************/

void

ADC_setup(

void

)

{

/* Enable ADC clock (This seems to be a duplicate statement) */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

/*********************************************************/

/* Configure ADC Channel 12 pin as analog input */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;

GPIO_Init(GPIOC, &GPIO_InitStructure);

/*** ADC1 regular channel 12 configuration ***/

ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

ADC_InitStructure.ADC_ScanConvMode = DISABLE;

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfConversion = 1;

ADC_Init(ADC1, &ADC_InitStructure);

ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, ADC_SampleTime_3Cycles);

/* Enable ADC1 */

ADC_Cmd(ADC1, ENABLE);

}

/*Read potentiometer (voltage) value*/

int

POTGetValue(

void

)

{

ADC_SoftwareStartConv(ADC1);

while

(ADC_GetSoftwareStartConvStatus(ADC1));

return

ADC_GetConversionValue(ADC1);

}

/****************************************************************************************/

int

main(

void

)

{

ADC_setup();

int

val1 = POTGetValue();

puts(val1);

}

It works

, Now i want to display many ADC

conversion for example i want to connect

4 signal to 4 port PC0

, P

C

1,

PC2

A

ND PC3.

what are the

modifications to do please ?

I fo

und in d

atasheet t

hat PC2 represent

ADC_Channel_12

th

at's why i use it

And i use in ligne 19 one

numbe

r

of

conversion

Thank you

#stm32f4discovery #adc

10 REPLIES 10
Posted on January 22, 2013 at 17:03

Your C, and basic flow need work.
 DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC1ConvertedValue[0];
..
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
..
int main(void)
{
// Don't repeatedly initialize
ADC_setup();
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConv(ADC1);
while(1)
{
Display (ADC1ConvertedValue[0]);
Display (ADC1ConvertedValue[1]);
}
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..