Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need a help for STM32f051 ADC Code

Status
Not open for further replies.

mousivand

Newbie level 4
Joined
Feb 5, 2013
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,334
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,
 

1.
You have a variable j. Is it declared as int or long_int? 8 bit, 16 bit, or 32 bit? It's compared to 2000000 which is more than 16 bits for a decimal figure.

2.
Your WHILE statements appear to be a compound expression. I'm not saying it's incorrect but it might help if you were to evaluate each expression on a separate line, and set a different flag variable for each, to make it easier to watch how many times the loop executes, and what makes it exit. (Does the WHILE loop require a WEND statement at the end?)

3.
Add verbose reporting of values so you can watch that the program is executing properly. That loops execute the proper number of times. That loops exit when they should. Etc.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top