Problem with adc of stm32f051

Thread Starter

Mousivandhossein

Joined Dec 8, 2020
34
Hi,
Happy new year

I want to use adc of stm32f051c8t6, but my code did not work correctly.
Code:
int main()
{
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
ADC1->CR |=ADC_CR_ADCAL;
while (ADC1->CR & ADC_CR_ADCAL);
ADC1->CR |=ADC_CR_ADEN;
ADC1->CHSELR |=ADC_CHSELR_CHSEL0;

RCC->APB1ENR |=RCC_APB1ENR_DACEN;
DAC->CR |=DAC_CR_EN1;


while(1)
{
ADC1->CR |= ADC_CR_ADSTART; /* Start the ADC conversion */
while (!(ADC1->ISR & ADC_ISR_EOC)); /* Wait end of conversion */
adc0 = ADC1->DR;
for(int j=0;j<2000000;j++)j=j;
}
}
I use adc channel 0 to read the voltage, but the result is zero.
Can you please help me?

Thanks and Best Regards,
 

MrChips

Joined Oct 2, 2009
30,806
You do not say what toolset you are using.
You do not show all your #include statements.
You did not select which pins to be used as ADC inputs.
... for starters.
 
Top