Question
Multi Channel ADC reading.
Posted on September 14, 2013 at 02:04
Hello,
I tried to read two analog inputs from PA3(ADC1_IN3) and PA5(ADC1_IN5). I expected tmpADC[0] has the input data of PA3 and tmpADC[1] has the input data of PA5. However, both tmpADC[0] and tmpADC[1] always have the input data of PA3. I read reference manual multiple times, but I couldn't figure out what is wrong. Please let me know what is problem. I attached my code below(only ADC part). Thanks &sharpinclude <stm32f4xx.h> void ADC_Init(void) { GPIOA->MODER |= (3UL<<6)|(3UL<<10); /*Set PA3 as an analog input, ADC1_IN3, Set PA5 as an analog input ADC1_IN5*/ GPIOA->PUPDR &= ~((3UL<<6)|(3UL<<10)); /*No Pull up and down resistor*/ RCC->APB2ENR =(1<<8); /*ADC1 clk enable*/ ADC1->CR1 = 0; ADC1->CR2 = (1UL<<0)| /*ADC1 power on */ (1UL<<1); /*Continuous conversion*/ ADC1->SMPR1 = 0; ADC1->SMPR2 = 0; ADC1->SQR1 = (1<<20); /* sequence length: two regular conversions*/ ADC1->SQR2 = 0; ADC1->SQR3 = (3UL<<0)|(5UL<<5); /*1st conversion = ADC1_lN3, 2nd conversion = ADC1_IN5*/ ADC->CCR = (1UL<<16); /*fpclk2/4 = 21Mhz */ } short unsigned int get_ADC(void) { ADC1->CR2 |= (1<<30); while(!(ADC1->SR & 0x2)); return ADC1->DR; } int main (void) { tmpADC[0] = get_ADC(); // expecting have data from ADC1_IN3 tmpADC[1] = get_ADC(); //expecting have data from ADC1_IN5 } #stm32f4 #discovery-board #adc-dma