Subversion Repositories HomeAutomation

Rev

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