AnsweredAssumed Answered

stm32f0 ADC internal temperature sensor

Question asked by German Tsvetkov on Nov 10, 2017
Latest reply on Nov 10, 2017 by German Tsvetkov

Hello. 

I need read temperature from internal sensor. But when i use code from examples, all time i have result more then 30 degrees of Celsius(~1760 - factory calibration value, ~1740 - ADC value in cold start with ~25 degrees in room). 

How i can read the real temperature of MCU?

 

It's my init code. ADC start conversion by software and read result in interrupt. 

#define TEMP30_CAL_ADDR             ((uint16_t*) ((uint32_t)0x1FFFF7B8)) // = 1767
#define TEMP110_CAL_ADDR             ((uint16_t*) ((uint32_t)0x1FFFF7C2)) // = 1310

void init_periph_adc()
{
    // Enable clock on ADC
    RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
    RCC->CR2 |= RCC_CR2_HSI14ON;
    while ((RCC->CR2 & RCC_CR2_HSI14RDY) == 0)
        ;

    // Start calibration of ADC
    ADC1->CR |= ADC_CR_ADDIS;
    while ((ADC1->CR & ADC_CR_ADEN) != 0)
        ;//TODO: make time management
    ADC1->CR |= ADC_CR_ADCAL;
    // Wait and of calibration
    while ((ADC1->CR & ADC_CR_ADCAL) != 0)
        ; //TODO: make time management

    // Select discontinious mode
    ADC1->CFGR1 |= ADC_CFGR1_DISCEN;
    // Select sampling mode
    ADC1->SMPR |= ADC_SMPR_SMP_0 | ADC_SMPR_SMP_1 | ADC_SMPR_SMP_2;

    //Enable temp sensor
    ADC->CCR |= ADC_CCR_TSEN;

    // Enable ADC interrupts
    ADC1->IER |= ADC_IER_EOCIE;
    // Set interrupt priority
    NVIC_SetPriority(ADC1_IRQn, 2);
    // Enable IRQ on NVIC
    NVIC_EnableIRQ(ADC1_IRQn);

    //Enable ADC
    ADC1->CR |= ADC_CR_ADEN;
}

Outcomes