English
Language : 

RM0376 Datasheet, PDF (928/968 Pages) STMicroelectronics – This reference manual targets application developers
Code examples
RM0376
A.8.16
A.8.17
Temperature configuration code example
/* (1) Select HSI16 by writing 00 in CKMODE (reset value) */
/* (2) Select continuous mode */
/* (3) Select CHSEL18 for temperature sensor */
/* (4) Select a sampling mode of 111 i.e. 239.5 ADC clk to be greater
than 2.2us */
/* (5) Wake-up the Temperature sensor (only for Temp sensor and
VRefInt) */
/* (6) Enable Sensor buffer for ADC by setting both ENBUF_SENSOR_ADC bit
and EN_VREFINT in SYSCFG_CFGR3 */
/* (7) Wait for SENSOR ADC buffer ready */
//ADC1->CFGR2 &= ~ADC_CFGR2_CKMODE; /* (1) */
ADC1->CFGR1 |= ADC_CFGR1_CONT; /* (2) */
ADC1->CHSELR = ADC_CHSELR_CHSEL18; /* (3) */
ADC1->SMPR |= ADC_SMPR_SMP; /* (4) */
ADC->CCR |= ADC_CCR_TSEN; /* (5) */
SYSCFG->CFGR3 |= SYSCFG_CFGR3_ENBUF_SENSOR_ADC
| SYSCFG_CFGR3_EN_VREFINT; /* (6) */
while ((SYSCFG->CFGR3 & SYSCFG_CFGR3_SENSOR_ADC_RDYF) == 0) /* (7) */
{
/* For robust implementation, add here time-out management */
}
Temperature computation code example
/* Temperature sensor calibration value address */
#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);
}
928/968
DocID025941 Rev 2