How to read values from the potentiometer through ADC in STM32f4?

0

I am trying to read the values from potentiometer which is connected to pin A0 (ADC channel 0 of STM32f407VG discovery board). I have attached my code. The problem is that, the values that I read are not only constant, but also aren't affected by the rotation of potentiometer. Although I have searched a lot, I couldn't manage to solve the problem. Can you help me to find the wrong part in my code? Thank you very much.

GPIOA->MODER |= GPIO_MODER_MODE0_Msk; //Set as PA0 as Analog Mode

RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; //Enable the ADC clock

ADC1->SQR1 = 0x00000000; //1 Convertion
ADC1->SQR2 = 0x00000000; 
ADC1->SQR3 = 0x00000000; //0'th channel will be converted first

ADC1->SMPR2 = 0x00000005; //sampling time - 112 cycles
ADC1->CR2 |= ADC_CR2_CONT_Msk; //Enable continious mode
ADC1->CR1 &= ~(ADC_CR1_SCAN_Msk); //Disable Scan mode
ADC1->CR2 |= ADC_CR2_ADON; //Enable ADC

while(1)
{
    ADC1->CR2 |= ADC_CR2_SWSTART_Msk; //Start convertion
    LCDSendAnInteger((ADC1->DR), 7); //Display value in LCD
    notExactTimeDelay(1000000);
    LCDClearDisplay();
}
arm
keil
stm32f4discovery
adc
asked on Stack Overflow Apr 4, 2019 by BHOS

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0