Electronic – STM32F103 – internal temperature sensor ADC doesn’t change value

adcmicrocontrollerstm32stm32f10xtemperature

I am currently trying to get the ADC of a STM32F103 running. My first exercise is to read the internal temperature sensor. This is my current approach:

void initADC(){
    RCC->APB2ENR |= (1<<9);      //Enable ADC1 Clock
    RCC->CFGR |= (0b10<<14);     //set ADC Prescaler '6'
    ADC1->CR1 |= (1<<4);         //Input Channel 16
    ADC1->SMPR1 |= (0b100<<18);  //41.5 cycles sample time
    ADC1->CR2 |= (1<<23);        //Enable Temperature Sensor & Vref

    ADC1->CR2 |= (1<<0);         //Enable ADC and start conversion

    ADC1->CR2 |= (1<<3);         //Initialize calibration register
    while(ADC1->CR2 & (1<<3)){   //Wait until calibration register initialized
        ;
    }

    ADC1->CR2 |= (1<<2);         //Enable calibration
    while(ADC1->CR2 & (1<<2)){   //Wait until calibration completed
        ;
    }
}

uint32_t getADCTempValue(){
    ADC1->CR2 |= (1<<0);         //Enable ADC and start conversion
    while(!(ADC1->SR & (1<<1))){ //Wait until end of conversion
        ;
    }
    return ADC1->DR;
}

These are some sample values I get:

2428 2417 2412 2400 2389 2381 2376 2380 2392 2406 2410

But no matter what I do (touching the controller, blowing at the controller) the value doesn't change significantly.

Best Answer

You channel selection is wrong. In the ADC_CR1, you can enable analog watchdog on the selected channels. But it does not enable the channel itself only the watchdog, Page 240.

enter image description here

To select a channel you must use ADC_SQRx or ADC_JSQR registers, depending wether regular or injected group is needed, Page 218.

enter image description here