STM32F407 ADC LOWER LEVEL PROGRAMMING ISSUE
Hi Everyone,
I m interested in doing lower level programming. Now i currently working with stm32f407 board. I have successfully got the output for GPIO. Now i am started working on ADC interface. But i couldnt get the output for my code. I haD given 3V to PA1 pin but still i couldnt get the proportional value in DR register. Kindly help me out to solve this issue.
&sharpinclude 'stm32f4xx.h'
void GPIO_Init(void);void adc_init(void);
uint16_t adc_read();
uint16_t adc_value1=0,adc_value2=0;int main(void)
{ GPIO_Init(); adc_init();while (1)
{ adc_value2=adc_read(); if(adc_value2>=0X000C) { GPIOD->ODR|=(1<<14); } else { GPIOD->ODR|=(1<<15); } // // GPIOD->ODR&=~(1<<14);// for(delay=0;delay<=4166666;delay++);// GPIOD->ODR|=(1<<15);
// for(delay=0;delay<=4166666;delay++);// // GPIOD->ODR&=~(1<<15);// for(delay=0;delay<=4166666;delay++);}
}
void GPIO_Init(void)
{RCC->AHB1ENR |=(1<<1); // clock for gpioA
GPIOA->MODER |= 0X03; // PA1 analog inputs }void adc_init(void)
{ RCC->APB2ENR|=(1<<8); ADC1->CR1|=(1<<24)|(1<<0); // 1st CHANNEL // 10BIT RESOLUTION ADC1->CR2|=(1<<10);// ADC1->CR2 ADC1->SMPR2 |= 1; //15 cycles ADC1->SQR1 &= ~(1<<20); // 1 conversion ADC1->SQR3 = 0x00; }uint16_t adc_read()
{ ADC1->CR2|=(1<<0);// ADC ON ADC1->CR2|=(1<<30);// START CONVERSION // if((ADC1->SR&(1<<1))) // wait untill EOC bit clear //{ ADC1->SR = 0X00; adc_value1=ADC1->DR; //} ADC1->CR2&=~(1<<0);// ADC OFF return(adc_value1);}#stm32f407-discovery-startup #learning-stm32 #stm32-l4