AnsweredAssumed Answered

Problem to get internal temperature STM32L0

Question asked by Simon NOWAK on Feb 22, 2017
Latest reply on Feb 24, 2017 by Simon NOWAK

Hi everyone, 

 

I'm trying to get the internal temperature on my STM32L0.
I have write the major part of the script but unfortunally the reading value is 0.
Does anyone can have a look on my script and tel me if you see something ?
Thank you very much for your help

Regards 
Simon

 

#define TEMP130_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FF8007E))
#define TEMP30_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FF8007A))
#define VDD_CALIB ((uint16_t) (300))
#define VDD_APPLI ((uint16_t) (330))

 

int32_t ComputeTemperature(uint32_t measure)
{
      int32_t temperature;
      temperature = ((measure * VDD_APPLI / VDD_CALIB) - (int32_t)*TEMP30_CAL_ADDR );
      temperature = temperature *(int32_t)(130-30);
      temperature = temperature /(int32_t)(*TEMP130_CAL_ADDR -*TEMP30_CAL_ADDR);
      temperature = temperature + 30;
      return(temperature);
}

 

void ConfigTemperature(void){
      //ADC Ready
      ADC1->ISR |= ADC_ISR_ADRDY;
      //Activation of the clock
      RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
      //Continuous mode
      ADC1->CFGR1 |= ADC_CFGR1_CONT;
      //Channel temp sensor
      ADC1->CHSELR |= ADC_CHANNEL_TEMPSENSOR;
      //Select the sample time
      ADC1->SMPR |= ADC_SMPR_SMP_1;
      //Turn on the temp sensor
      ADC->CCR |= ADC_CCR_TSEN;
      wait(1);
      //Start the conversion
      ADC1->CR |= ADC_CR_ADSTART;
      wait(1);
      pcMain.printf("%Measure %i\n\r", measure);
      pcMain.printf("%The temperature value is %i\n\r",ComputeTemperature(measure));
}

 

int main(void)
{
      ConfigTemperature();
}

Outcomes