Question
Read potentiometer Value ?
Posted on December 29, 2012 at 15:19
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