46 #include <util/crc16.h>
49 #include "sensor_defs.h"
75 #if !defined(DS18B20_NB)
76 # define DS18B20_NB (1)
77 # define DS18B20_ADDR {0}
82 #define DS18B20_PARASITE_POWER (1)
84 #define DS18B20_DEBUG (0)
85 #if DS18B20_DEBUG == 1
87 # define DBG(...) PRINTF(__VA_ARGS__)
88 # define DBGP(x) PRINT(x)
96 #define DS18B20_CONV_TIME_MS (188)
97 #define DS18B20_COPYSCRATCH_TIME_MS (20)
98 #define DS18B20_SIZE_SCRATCHPAD (9)
100 #define DS18B20_FUNCCMD_CONVT (0x44)
101 #define DS18B20_FUNCCMD_READSCRATCH (0xBE)
102 #define DS18B20_FUNCCMD_WRITESCRATCH (0x4E)
103 #define DS18B20_FUNCCMD_COPYSCRATCH (0x48)
104 #define DS18B20_FUNCCMD_RECALLEE (0xB8)
105 #define DS18B20_FUNCCMD_READPOWER (0xB4)
132 uint8_t rv = SENSOR_ERR_OK;
136 case DS18B20_FUNCCMD_CONVT :
138 case DS18B20_FUNCCMD_READSCRATCH:
140 DBGP(
"read scratch:");
144 DBG(
"0x%02x ", *buf);
145 crc = _crc_ibutton_update(crc, *buf++);
147 DBG(
"crc = 0x%x\n", crc);
153 case DS18B20_FUNCCMD_WRITESCRATCH:
155 case DS18B20_FUNCCMD_COPYSCRATCH:
156 #if defined(DS18B20_PARASITE_POWER)
161 case DS18B20_FUNCCMD_RECALLEE:
163 case DS18B20_FUNCCMD_READPOWER:
182 uint8_t buf[DS18B20_SIZE_SCRATCHPAD];
183 uint8_t rv = SENSOR_ERR_OK;
188 _delay_ms(DS18B20_CONV_TIME_MS);
204 #if defined(DS18B20_PARASITE_POWER)
210 #if defined(DS18B20_PARASITE_POWER)
216 if (rv == SENSOR_ERR_OK)
218 *temp = ( ((int16_t)buf[1] << 8)| ((int16_t)buf[0] << 0) )/16;
244 if (temp == 85 && err == SENSOR_ERR_OK)
251 err = SENSOR_ERR_PWRON;
253 if (err == SENSOR_ERR_OK)
268 DBG(
"ds18b20_get_val: temp=%d, rv=%d, err=%d\n\r", temp, rv, err);
275 static inline uint8_t ds18b20_get_raw(
void *pctx, uint8_t *pdata)
280 static inline void ds18b20_sleep(
void *pctx)
294 ow_serial_t tmp_addr[
DS18B20_NB] = DS18B20_ADDR;
299 pcfg->g.id = SENSOR_DS18B20;
300 pcfg->g.f_trigger = NULL;
302 pcfg->g.f_sleep = NULL;
306 memcpy(pcfg->addr, tmp_addr,
sizeof(tmp_addr));
static uint8_t sensor_create_ds18b20(void *pdata, bool raw)
static uint8_t ds18b20_get_val(void *pctx, uint8_t *pdata)
void ow_master_matchrom(ow_serial_t ser)
static uint8_t ds18b20_command(uint8_t command, uint8_t *buf)
static void ds18b20_trigger(void *pctx, bool one_shot)
uint8_t ow_byte_read(void)
void ow_byte_write(uint8_t byte)
static uint8_t ds18b20_read_temperature(ow_serial_t ser, int16_t *temp)