cancel
Showing results for 
Search instead for 
Did you mean: 

Problem to get internal temperature STM32L0

Simon NOWAK
Associate II

Posted on February 22, 2017 at 10:26

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

&sharpdefine TEMP130_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FF8007E))

&sharpdefine TEMP30_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FF8007A))

&sharpdefine VDD_CALIB ((uint16_t) (300))

&sharpdefine 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();

}

10 REPLIES 10

Have you looked at the examples in CubeL0? [EDIT] https://github.com/STMicroelectronics/STM32CubeL0/tree/master/Projects/NUCLEO-L053R8/Examples/ADC/ADC_Sequencer [/EDIT]

Or maybe it can be clicked in CubeMX.

> This should not be a science project.

Of course not, it's normal programming - you read the manual and program it accordingly.

JW