2012-12-29 06:19 AM
Hi,
I want to program a potentiometer connected in PC2 as input usingSTM32F4
I use this programGPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
/***********************************************
/* 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);
/* Enable ADC1 /***********************************************
ADC_Cmd(ADC1, ENABLE);
* Read potentiometer (voltage) value
*/
int
POTGetValue(
void
)
{
ADC_SoftwareStartConv(ADC1);
while
(ADC_GetSoftwareStartConvStatus(ADC1));
return
ADC_GetConversionValue(ADC1);
}
Did someone know what is missing her because i can't read anything if i write ''
POTGetValue
'' in main
Thanks
2012-12-29 06:38 AM
Did someone know what is missing here because i can't read anything if i write ''POTGetValue'' in main
Like configuring the channel you want to sample? /* ADC1 regular channel12 configuration *************************************/ ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, ADC_SampleTime_3Cycles);
2012-12-29 06:44 AM
I have to add this line to my program ?
2012-12-29 07:24 AM
I add this line to my program and the problem persist
Reading potentiometer Value gives always 02012-12-29 07:44 AM
Like changing the ADC Enable line from a comment to executable code.
Cheers, Hal2012-12-29 10:41 AM
Yes it's uncomment just error of paste text in the forum.
2012-12-29 12:28 PM
It works !
This line is missing in my program
/* Enable ADC clock (This seems to be a duplicate statement) */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
Thank you