Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

  1. #ifndef DS18X20_H_
  2. #define DS18X20_H_
  3.  
  4. #include <stdlib.h>
  5. #include <inttypes.h>
  6. #include <onewire.h>
  7.  
  8. // enable DS18x20 EERPROM support
  9. //#define DS18X20_EEPROMSUPPORT
  10.  
  11. // enable extended output via UART by defining:
  12. //#define DS18X20_VERBOSE
  13.  
  14. /* return values */
  15. #define DS18X20_OK          0x00
  16. #define DS18X20_ERROR       0x01
  17. #define DS18X20_START_FAIL  0x02
  18. #define DS18X20_ERROR_CRC   0x03
  19.  
  20. #define DS18X20_POWER_PARASITE 0x00
  21. #define DS18X20_POWER_EXTERN   0x01
  22.  
  23. /* DS18X20 specific values (see datasheet) */
  24. #define DS18S20_ID 0x10
  25. #define DS18B20_ID 0x28
  26.  
  27. #define DS18X20_CONVERT_T   0x44
  28. #define DS18X20_READ        0xBE
  29. #define DS18X20_WRITE       0x4E
  30. #define DS18X20_EE_WRITE    0x48
  31. #define DS18X20_EE_RECALL   0xB8
  32. #define DS18X20_READ_POWER_SUPPLY 0xB4
  33.  
  34. #define DS18B20_CONF_REG    4
  35. #define DS18B20_9_BIT       0
  36. #define DS18B20_10_BIT      (1<<5)
  37. #define DS18B20_11_BIT      (1<<6)
  38. #define DS18B20_12_BIT      ((1<<6)|(1<<5))
  39.  
  40. // indefined bits in LSB if 18B20 != 12bit
  41. #define DS18B20_9_BIT_UNDF       ((1<<0)|(1<<1)|(1<<2))
  42. #define DS18B20_10_BIT_UNDF      ((1<<0)|(1<<1))
  43. #define DS18B20_11_BIT_UNDF      ((1<<0))
  44. #define DS18B20_12_BIT_UNDF      0
  45.  
  46. // conversion times in ms
  47. #define DS18B20_TCONV_12BIT      750
  48. #define DS18B20_TCONV_11BIT      DS18B20_TCONV_12_BIT/2
  49. #define DS18B20_TCONV_10BIT      DS18B20_TCONV_12_BIT/4
  50. #define DS18B20_TCONV_9BIT       DS18B20_TCONV_12_BIT/8
  51. #define DS18S20_TCONV            DS18B20_TCONV_12_BIT
  52.  
  53. // constant to convert the fraction bits to cel*(10^-4)
  54. #define DS18X20_FRACCONV         625
  55.  
  56. #define DS18X20_SP_SIZE  9
  57.  
  58. // DS18X20 EEPROM-Support
  59. #define DS18X20_WRITE_SCRATCHPAD  0x4E
  60. #define DS18X20_COPY_SCRATCHPAD   0x48
  61. #define DS18X20_RECALL_E2         0xB8
  62. #define DS18X20_COPYSP_DELAY      10 /* ms */
  63. #define DS18X20_TH_REG      2
  64. #define DS18X20_TL_REG      3
  65.  
  66. /*
  67.  * Eget ditfulat av eqlazer
  68.  */
  69. #define MAXSENSORS 4
  70.  
  71. uint8_t gSensorIDs[MAXSENSORS][OW_ROMCODE_SIZE];
  72.  
  73. extern uint8_t search_sensors(void);
  74.  
  75.  
  76. /* for description of functions see ds18x20.c */
  77.  
  78. extern void DS18X20_find_sensor(uint8_t *diff,
  79.     uint8_t id[]);
  80.    
  81. extern uint8_t  DS18X20_get_power_status(uint8_t id[]);
  82.  
  83. extern uint8_t DS18X20_start_meas( uint8_t with_external,
  84.     uint8_t id[]);
  85. extern uint8_t DS18X20_read_meas(uint8_t id[],
  86.     uint8_t *subzero, uint8_t *cel, uint8_t *cel_frac_bits);
  87. extern uint8_t DS18X20_read_meas_single(uint8_t familycode,
  88.     uint8_t *subzero, uint8_t *cel, uint8_t *cel_frac_bits);
  89.  
  90. extern uint8_t DS18X20_meas_to_cel( uint8_t fc, uint8_t *sp,
  91.     uint8_t* subzero, uint8_t* cel, uint8_t* cel_frac_bits);
  92. extern  uint16_t DS18X20_temp_to_decicel(uint8_t subzero, uint8_t cel,
  93.     uint8_t cel_frac_bits);
  94. extern int8_t DS18X20_temp_cmp(uint8_t subzero1, uint16_t cel1,
  95.     uint8_t subzero2, uint16_t cel2);
  96.  
  97. #ifdef DS18X20_EEPROMSUPPORT
  98. // write th, tl and config-register to scratchpad (config ignored on S20)
  99. uint8_t DS18X20_write_scratchpad( uint8_t id[],
  100.     uint8_t th, uint8_t tl, uint8_t conf);
  101. // read scratchpad into array SP
  102. uint8_t DS18X20_read_scratchpad( uint8_t id[], uint8_t sp[]);
  103. // copy values th,tl (config) from scratchpad to DS18x20 eeprom
  104. uint8_t DS18X20_copy_scratchpad( uint8_t with_power_extern,
  105.     uint8_t id[] );
  106. // copy values from DS18x20 eeprom to scratchpad
  107. uint8_t DS18X20_recall_E2( uint8_t id[] );
  108. #endif
  109.  
  110. #ifdef DS18X20_VERBOSE
  111. extern void DS18X20_show_id_uart( uint8_t *id, size_t n );
  112. extern uint8_t DS18X20_read_meas_all_verbose( void );
  113. #endif
  114.  
  115. #endif
  116.