Question
ADC Conversion
Posted on October 12, 2010 at 13:22
hi.
i am trying to activate the adc module with the following program : __IO uint16_t ADCConvertedValue; int main(void) { int temp=0; setsystemclock(); //set system clock to 24Mhz3 //rcc CONFIGURATION RCC->AHBENR=RCC_AHBENR_DMA1EN; //dma clock enable RCC->APB2ENR=RCC_APB2ENR_IOPCEN | RCC_APB2ENR_ADC1EN; //portc and ADC clock enable. //GPIO CONFIGURATION GPIOC->CRL=0x0;// ADC1_IN14 // DMA configuration: DMA1_Channel1->CCR= DMA_CCR1_CIRC | DMA_CCR1_PSIZE_0 | DMA_CCR1_MSIZE_0 | DMA_CCR1_PL_1; //Circular mode,Read from peripheral,Peripheral size 16-bits, Memory size 16-bits, Channel priority level High. DMA1_Channel1->CNDTR=1; //bytes to be transmitted. Check only 1 channel DMA1_Channel1->CPAR = 0x4001244C; //adc address DMA1_Channel1->CMAR=(uint32_t)&ADCConvertedValue; DMA1_Channel1->CCR |= CCR_ENABLE_Set; //ADC configuration ADC1->CR1=ADC_CR1_SCAN; ADC1->CR2=ADC_CR2_ALIGN | ADC_CR2_EXTSEL ; //data align right , software start ADC1->SMPR1=0;// 1.5 cycles conversion time ADC1->SQR3=0; ADC1->SQR1|=ADC_SQR1_SQ14_0; ADC1->CR2 |=ADC_CR1_SCAN ; /* Enable ADC1 DMA */ ADC1->CR2 |=ADC_CR2_ADON; /* Enable ADC1 */ ADC1->CR2 |=ADC_CR2_RSTCAL ;//reset calibration while ((ADC1->CR2 & ADC_CR2_RSTCAL) != 0x00); //wait for end of ADC1 reset calibration register ADC1->CR2 |=ADC_CR2_CAL;/* Start ADC1 calibaration */ while((ADC1->CR2 & ADC_CR2_CAL) != 0x00);/* Check the end of ADC1 calibration */ ADC1->CR2 |=ADC_CR2_SWSTART |ADC_CR2_EXTTRIG; /* Start ADC1 Software Conversion */ while(1) { if((ADC1->SR&ADC_SR_EOC)>0) { temp=ADC1->DR; ADC1->CR2 |=ADC_CR2_SWSTART |ADC_CR2_EXTTRIG; /* Start ADC1 Software Conversion */ temp=temp+1; } } } but if i put GND in PC4 which is channel 14 i dont get zero in ADC1->DR. why what am i doing wrong? thanks.