annotate 1wire.h @ 85:18b154c447bb

Add note about 1-wire wiring
author Daniel O'Connor <darius@dons.net.au>
date Thu, 12 Mar 2015 23:22:11 +1030
parents cc998b0b2bae
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 /*
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2 * 1 wire header which defines functions and constants
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 *
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 * $Id$
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 *
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 * Copyright (c) 2004
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 * Daniel O'Connor <darius@dons.net.au>. All rights reserved.
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 *
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 * Redistribution and use in source and binary forms, with or without
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10 * modification, are permitted provided that the following conditions
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11 * are met:
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 * 1. Redistributions of source code must retain the above copyright
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer.
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 * 2. Redistributions in binary form must reproduce the above copyright
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 * notice, this list of conditions and the following disclaimer in the
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 * documentation and/or other materials provided with the distribution.
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 *
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 * SUCH DAMAGE.
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 */
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 #ifndef PROGMEM
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32 #define PROGMEM
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33 #endif
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 void OWInit(void);
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36 uint8_t OWTouchReset(void);
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37 void OWWriteBit(uint8_t bit);
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38 uint8_t OWReadBit(void);
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39 void OWWriteByte(uint8_t data);
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40 uint8_t OWReadByte(void);
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 uint8_t OWTouchByte(uint8_t data);
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42 void OWBlock(uint8_t *data, int len);
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
43 uint8_t OWFirst(uint8_t *ROM, uint8_t do_reset, uint8_t alarm_only);
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 uint8_t OWNext(uint8_t *ROM, uint8_t do_reset, uint8_t alarm_only);
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
45 void OWCRC(uint8_t x, uint8_t *crc);
68
cc998b0b2bae Handle missing modules in OWGetTemp.
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
46 uint8_t OWSendCmd(uint8_t *ROM, uint8_t cmd);
13
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
47 uint8_t OWProgROM(uint8_t *ROM, uint8_t start, uint8_t len, uint8_t *data, uint8_t exact, uint8_t status);
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
48 int16_t OWGetTemp(uint8_t *ROM);
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
49 const PROGMEM char *OWTempStatusStr(int16_t val, uint8_t shrt);
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
50 extern const PROGMEM char *OWProgROM_Status[];
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
51
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 /* Return codes for OWFirst()/OWNext() */
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
54 #define OW_BADWIRE -3
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
55 #define OW_BADCRC -2
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56 #define OW_NOPRESENCE -1
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
57 #define OW_NOMODULES 0
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
58 #define OW_FOUND 1
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
59
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
60 /* General 1 wire commands */
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
61 #define OW_OVRDRV_SKIP_CMD 0x3c
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62 #define OW_SEARCH_ALRM_CMD 0xec
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
63 #define OW_SEARCH_ROM_CMD 0xf0
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
64 #define OW_READ_ROM_CMD 0x33
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65 #define OW_MATCH_ROM_CMD 0x55
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
66 #define OW_SKIP_ROM_CMD 0xcc
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
67
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
68 /* DS1820 commands */
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
69 #define OW_CONVERTT_CMD 0x44
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70 #define OW_RD_SCR_CMD 0xbe
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71 #define OW_WR_SCR_CMD 0x4e
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
72 #define OW_CPY_SCR_CMD 0x48
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
73 #define OW_RECALL_CMD 0xb8
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
74 #define OW_RD_PSU_CMD 0xb4
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
76 /* DS2502 commands */
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77 #define OW_READ_MEMORY 0xf0
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
78 #define OW_READ_STATUS 0xaa
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
79 #define OW_GEN_CRC 0xc3
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80 #define OW_WRITE_MEMORY 0x0f
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81 #define OW_WRITE_STATUS 0x55
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83 /* Family codes */
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84 #define OW_FAMILY_ROM 0x09
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85 #define OW_FAMILY_TEMP 0x10
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
87 /* Return codes for OWGetTemp */
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
88 #define OW_TEMP_BADVAL -6000
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
89 #define OW_TEMP_WRONG_FAM -6001
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
90 #define OW_TEMP_CRC_ERR -6002
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
91 #define OW_TEMP_NO_ROM -6003
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
93 /* Helpers for OWGetTemp's number system */
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94 #define GETWHOLE(x) ((x) / 100)
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95 #define GETFRAC(x) abs((x) - (GETWHOLE(x) * 100))