cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in single conversion mode in ADC

DivyaJayan
Associate II

Hi, 

While implementing a single conversion process for the Analog-to-Digital Converter (ADC) via register-level programming, the debugging phase yields a consistent output of zero, irrespective of the input. This anomaly persists even after the ADC input pin PC0 is alternated between a ground (GND) connection and a 3.3V supply, indicating no variation in the output value.

I am using Nucleo-L476RG evaluation board.

Please help.

Here is my code:

#define ADCEN         (1U << 13)
#define GPIOCEN       (1U << 2)
#define ADC_CH1       (1U << 6)
#define ADC_SEQ_LEN_1 0x000
#define CR_ADEN       (1U << 0)
#define CR_ADSTART    (1U << 2)
#define ISR_EOC       (1U << 2)
#define CR_ADCAL      (1U << 31)

void pc0_adc1_init(){

	RCC -> AHB2ENR |= GPIOCEN;

	GPIOC -> MODER |= (1U << 0);
	GPIOC -> MODER |= (1U << 1);

	RCC -> AHB2ENR |= ADCEN;

	ADC1 -> CR &= ~CR_ADEN;
	ADC1 -> CR |= CR_ADCAL;

    while(ADC1 -> CR & CR_ADCAL){}

	ADC1 -> SQR1 |= ADC_CH1;
	ADC1 -> SQR1 |= ADC_SEQ_LEN_1;

	ADC1 ->CR |= CR_ADEN;

}

void adc_conversion(void){

	ADC1 -> CFGR |= CFGR_CONT;
	ADC1 -> CR |= CR_ADSTART;
}

uint32_t adc_read(void){

	while(!(ADC1 -> ISR & ISR_EOC)){}
	return (ADC1 -> DR);
}

uint32_t sensor_value;

int main(void){


	pc0_adc1_init();
	adc_conversion();

	while(1){
		sensor_value = adc_read();
	}
}

 

Screenshot 2024-07-03 104049.png

 

0 REPLIES 0