Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /#define TEMP130_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FF8007E))
- /#define TEMP30_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FF8007A))
- /#define test ((uint32_t*) ((uint32_t) 0x0000FFFFU))
- /#define VDD_CALIB ((uint16_t) (300))
- /#define VDD_APPLI ((uint16_t) (330))
- void ConfigTemperature(void){
- ADC1->CFGR1 |= ADC_CFGR1_CONT;
- ADC1->CHSELR = ADC_CHSELR_CHSEL18;
- ADC1->SMPR |= ADC_SMPR_SMP;
- ADC->CCR |= ADC_CCR_TSEN;
- wait(1);
- }
- 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 showTemp(){
- ADC1->CFGR1 |= ADC_CFGR1_CONT;
- ADC1->CHSELR = ADC_CHSELR_CHSEL18;
- ADC1->SMPR |= ADC_SMPR_SMP;
- ADC->CCR |= ADC_CCR_TSEN;
- wait(1);
- uint32_t measure = ADC1->DR;
- pc.printf("%inr",ComputeTemperature(measure));
- }
- int main(void){
- ConfigTemp();
- showTemp();
- }
- /* (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) */
- //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) */
- /* 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)) // <-- change this to according to your supply voltage
- 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement