Thread Starter

Mousivandhossein

Joined Dec 8, 2020
25
Hi,

I want to use channel 3 and the internal temperature sensor of stm32f051.
I read the reference manual of the micro and I tried to use it, but unfortunately, my code does not work.

Please help me.

Thanks and Best Regards,
The code:
main:
#include <stm32f0xx.h>

short ADC_Result[2]={0,0};
char i=0;
int volt;                                         
int dam,temp;                                       

int main()
{
for(int j=0;j<200000;j++)j=j;            //delay
    
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_CHSEL3 | ADC_CHSELR_CHSEL16;
ADC->CCR |= ADC_CCR_TSEN;   
    
while(1)
{
            ADC1->CR |= ADC_CR_ADSTART;                 /* Start the ADC conversion */
            for (i=0; i < 2; i++)
            {
                while (!(ADC1->ISR & ADC_ISR_EOC));             /* Wait end of conversion */
                ADC_Result[i] = ADC1->DR;                                 /* Store the ADC conversion result */
            }
            volt=volt+ADC_Result[0];
            dam=ADC_Result[1]+dam;
    }
}
 
Top