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