Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. /#define TEMP130_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FF8007E))
  2. /#define TEMP30_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FF8007A))
  3. /#define test ((uint32_t*) ((uint32_t) 0x0000FFFFU))
  4. /#define VDD_CALIB ((uint16_t) (300))
  5. /#define VDD_APPLI ((uint16_t) (330))
  6.  
  7. void ConfigTemperature(void){
  8. ADC1->CFGR1 |= ADC_CFGR1_CONT;
  9. ADC1->CHSELR = ADC_CHSELR_CHSEL18;
  10. ADC1->SMPR |= ADC_SMPR_SMP;
  11. ADC->CCR |= ADC_CCR_TSEN;
  12. wait(1);
  13. }
  14.  
  15. int32_t ComputeTemperature(uint32_t measure)
  16. {
  17. int32_t temperature;
  18. temperature = ((measure * VDD_APPLI / VDD_CALIB) - (int32_t)*TEMP30_CAL_ADDR );
  19. temperature = temperature *(int32_t)(130-30);
  20. temperature = temperature /(int32_t)(*TEMP130_CAL_ADDR -*TEMP30_CAL_ADDR);
  21. temperature = temperature + 30;
  22. return(temperature);
  23. }
  24.  
  25. void showTemp(){
  26. ADC1->CFGR1 |= ADC_CFGR1_CONT;
  27. ADC1->CHSELR = ADC_CHSELR_CHSEL18;
  28. ADC1->SMPR |= ADC_SMPR_SMP;
  29. ADC->CCR |= ADC_CCR_TSEN;
  30. wait(1);
  31. uint32_t measure = ADC1->DR;
  32. pc.printf("%inr",ComputeTemperature(measure));
  33. }
  34.  
  35. int main(void){
  36. ConfigTemp();
  37. showTemp();
  38. }
  39.  
  40. /* (1) Select HSI16 by writing 00 in CKMODE (reset value) */
  41. /* (2) Select continuous mode */
  42. /* (3) Select CHSEL18 for temperature sensor */
  43. /* (4) Select a sampling mode of 111 i.e. 239.5 ADC clk to be greater
  44. than 2.2us */
  45. /* (5) Wake-up the Temperature sensor (only for Temp sensor and
  46. VRefInt) */
  47. //ADC1->CFGR2 &= ~ADC_CFGR2_CKMODE; /* (1) */
  48. ADC1->CFGR1 |= ADC_CFGR1_CONT;/* (2) */
  49. ADC1->CHSELR = ADC_CHSELR_CHSEL18;/* (3) */
  50. ADC1->SMPR |= ADC_SMPR_SMP;/* (4) */
  51. ADC->CCR |= ADC_CCR_TSEN;/* (5) */
  52.  
  53. /* Temperature sensor calibration value address */
  54. #define TEMP130_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FF8007E))
  55. #define TEMP30_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FF8007A))
  56. #define VDD_CALIB ((uint16_t) (300))
  57. #define VDD_APPLI ((uint16_t) (330)) // <-- change this to according to your supply voltage
  58.  
  59. int32_t ComputeTemperature(uint32_t measure)
  60. {
  61. int32_t temperature;
  62. temperature = ((measure * VDD_APPLI / VDD_CALIB) - (int32_t)*TEMP30_CAL_ADDR );
  63. temperature = temperature *(int32_t)(130-30);
  64. temperature = temperature /(int32_t)(*TEMP130_CAL_ADDR -*TEMP30_CAL_ADDR);
  65. temperature = temperature + 30;
  66. return(temperature);
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement