1-Wire implementation, using DS2480B controller interfaced with serial port, working example to read DS18B20, based on work already in progress / Dallas - Public domain code

Dependencies:   mbed

Committer:
pwheels
Date:
Thu Mar 24 17:21:29 2011 +0000
Revision:
0:1193dbfe28e2

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pwheels 0:1193dbfe28e2 1 //---------------------------------------------------------------------------
pwheels 0:1193dbfe28e2 2 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
pwheels 0:1193dbfe28e2 3 //
pwheels 0:1193dbfe28e2 4 // Permission is hereby granted, free of charge, to any person obtaining a
pwheels 0:1193dbfe28e2 5 // copy of this software and associated documentation files (the "Software"),
pwheels 0:1193dbfe28e2 6 // to deal in the Software without restriction, including without limitation
pwheels 0:1193dbfe28e2 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
pwheels 0:1193dbfe28e2 8 // and/or sell copies of the Software, and to permit persons to whom the
pwheels 0:1193dbfe28e2 9 // Software is furnished to do so, subject to the following conditions:
pwheels 0:1193dbfe28e2 10 //
pwheels 0:1193dbfe28e2 11 // The above copyright notice and this permission notice shall be included
pwheels 0:1193dbfe28e2 12 // in all copies or substantial portions of the Software.
pwheels 0:1193dbfe28e2 13 //
pwheels 0:1193dbfe28e2 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
pwheels 0:1193dbfe28e2 15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
pwheels 0:1193dbfe28e2 16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
pwheels 0:1193dbfe28e2 17 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
pwheels 0:1193dbfe28e2 18 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
pwheels 0:1193dbfe28e2 19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
pwheels 0:1193dbfe28e2 20 // OTHER DEALINGS IN THE SOFTWARE.
pwheels 0:1193dbfe28e2 21 //
pwheels 0:1193dbfe28e2 22 // Except as contained in this notice, the name of Dallas Semiconductor
pwheels 0:1193dbfe28e2 23 // shall not be used except as stated in the Dallas Semiconductor
pwheels 0:1193dbfe28e2 24 // Branding Policy.
pwheels 0:1193dbfe28e2 25 //---------------------------------------------------------------------------
pwheels 0:1193dbfe28e2 26 //
pwheels 0:1193dbfe28e2 27 // DS2480.H - This file contains the DS2480B constants
pwheels 0:1193dbfe28e2 28 //
pwheels 0:1193dbfe28e2 29 // Version: 2.00
pwheels 0:1193dbfe28e2 30 //
pwheels 0:1193dbfe28e2 31 // History: 1.02 -> 1.03 Make sure uchar is not defined twice.
pwheels 0:1193dbfe28e2 32 //
pwheels 0:1193dbfe28e2 33 //
pwheels 0:1193dbfe28e2 34
pwheels 0:1193dbfe28e2 35
pwheels 0:1193dbfe28e2 36 #ifndef DS2480_H
pwheels 0:1193dbfe28e2 37 #define DS2480_H
pwheels 0:1193dbfe28e2 38
pwheels 0:1193dbfe28e2 39 #include "ownet.h"
pwheels 0:1193dbfe28e2 40
pwheels 0:1193dbfe28e2 41 #ifndef __MC68K__
pwheels 0:1193dbfe28e2 42 #include <stdlib.h>
pwheels 0:1193dbfe28e2 43 #ifndef _WIN32_WCE
pwheels 0:1193dbfe28e2 44 #include <stdio.h>
pwheels 0:1193dbfe28e2 45 #endif
pwheels 0:1193dbfe28e2 46 #endif
pwheels 0:1193dbfe28e2 47
pwheels 0:1193dbfe28e2 48 // Mode Commands
pwheels 0:1193dbfe28e2 49 #define MODE_DATA 0xE1
pwheels 0:1193dbfe28e2 50 #define MODE_COMMAND 0xE3
pwheels 0:1193dbfe28e2 51 #define MODE_STOP_PULSE 0xF1
pwheels 0:1193dbfe28e2 52
pwheels 0:1193dbfe28e2 53 // Return byte value
pwheels 0:1193dbfe28e2 54 #define RB_CHIPID_MASK 0x1C
pwheels 0:1193dbfe28e2 55 #define RB_RESET_MASK 0x03
pwheels 0:1193dbfe28e2 56 #define RB_1WIRESHORT 0x00
pwheels 0:1193dbfe28e2 57 #define RB_PRESENCE 0x01
pwheels 0:1193dbfe28e2 58 #define RB_ALARMPRESENCE 0x02
pwheels 0:1193dbfe28e2 59 #define RB_NOPRESENCE 0x03
pwheels 0:1193dbfe28e2 60
pwheels 0:1193dbfe28e2 61 #define RB_BIT_MASK 0x03
pwheels 0:1193dbfe28e2 62 #define RB_BIT_ONE 0x03
pwheels 0:1193dbfe28e2 63 #define RB_BIT_ZERO 0x00
pwheels 0:1193dbfe28e2 64
pwheels 0:1193dbfe28e2 65 // Masks for all bit ranges
pwheels 0:1193dbfe28e2 66 #define CMD_MASK 0x80
pwheels 0:1193dbfe28e2 67 #define FUNCTSEL_MASK 0x60
pwheels 0:1193dbfe28e2 68 #define BITPOL_MASK 0x10
pwheels 0:1193dbfe28e2 69 #define SPEEDSEL_MASK 0x0C
pwheels 0:1193dbfe28e2 70 #define MODSEL_MASK 0x02
pwheels 0:1193dbfe28e2 71 #define PARMSEL_MASK 0x70
pwheels 0:1193dbfe28e2 72 #define PARMSET_MASK 0x0E
pwheels 0:1193dbfe28e2 73 #define VERSION_MASK 0x1C
pwheels 0:1193dbfe28e2 74
pwheels 0:1193dbfe28e2 75 // Command or config bit
pwheels 0:1193dbfe28e2 76 #define CMD_COMM 0x81
pwheels 0:1193dbfe28e2 77 #define CMD_CONFIG 0x01
pwheels 0:1193dbfe28e2 78
pwheels 0:1193dbfe28e2 79 // Function select bits
pwheels 0:1193dbfe28e2 80 #define FUNCTSEL_BIT 0x00
pwheels 0:1193dbfe28e2 81 #define FUNCTSEL_SEARCHON 0x30
pwheels 0:1193dbfe28e2 82 #define FUNCTSEL_SEARCHOFF 0x20
pwheels 0:1193dbfe28e2 83 #define FUNCTSEL_RESET 0x40
pwheels 0:1193dbfe28e2 84 #define FUNCTSEL_CHMOD 0x60
pwheels 0:1193dbfe28e2 85
pwheels 0:1193dbfe28e2 86 // Bit polarity/Pulse voltage bits
pwheels 0:1193dbfe28e2 87 #define BITPOL_ONE 0x10
pwheels 0:1193dbfe28e2 88 #define BITPOL_ZERO 0x00
pwheels 0:1193dbfe28e2 89 #define BITPOL_5V 0x00
pwheels 0:1193dbfe28e2 90 #define BITPOL_12V 0x10
pwheels 0:1193dbfe28e2 91
pwheels 0:1193dbfe28e2 92 // One Wire speed bits
pwheels 0:1193dbfe28e2 93 #define SPEEDSEL_STD 0x00
pwheels 0:1193dbfe28e2 94 #define SPEEDSEL_FLEX 0x04
pwheels 0:1193dbfe28e2 95 #define SPEEDSEL_OD 0x08
pwheels 0:1193dbfe28e2 96 #define SPEEDSEL_PULSE 0x0C
pwheels 0:1193dbfe28e2 97
pwheels 0:1193dbfe28e2 98 // Data/Command mode select bits
pwheels 0:1193dbfe28e2 99 #define MODSEL_DATA 0x00
pwheels 0:1193dbfe28e2 100 #define MODSEL_COMMAND 0x02
pwheels 0:1193dbfe28e2 101
pwheels 0:1193dbfe28e2 102 // 5V Follow Pulse select bits (If 5V pulse
pwheels 0:1193dbfe28e2 103 // will be following the next byte or bit.)
pwheels 0:1193dbfe28e2 104 #define PRIME5V_TRUE 0x02
pwheels 0:1193dbfe28e2 105 #define PRIME5V_FALSE 0x00
pwheels 0:1193dbfe28e2 106
pwheels 0:1193dbfe28e2 107 // Parameter select bits
pwheels 0:1193dbfe28e2 108 #define PARMSEL_PARMREAD 0x00
pwheels 0:1193dbfe28e2 109 #define PARMSEL_SLEW 0x10
pwheels 0:1193dbfe28e2 110 #define PARMSEL_12VPULSE 0x20
pwheels 0:1193dbfe28e2 111 #define PARMSEL_5VPULSE 0x30
pwheels 0:1193dbfe28e2 112 #define PARMSEL_WRITE1LOW 0x40
pwheels 0:1193dbfe28e2 113 #define PARMSEL_SAMPLEOFFSET 0x50
pwheels 0:1193dbfe28e2 114 #define PARMSEL_ACTIVEPULLUPTIME 0x60
pwheels 0:1193dbfe28e2 115 #define PARMSEL_BAUDRATE 0x70
pwheels 0:1193dbfe28e2 116
pwheels 0:1193dbfe28e2 117 // Pull down slew rate.
pwheels 0:1193dbfe28e2 118 #define PARMSET_Slew15Vus 0x00
pwheels 0:1193dbfe28e2 119 #define PARMSET_Slew2p2Vus 0x02
pwheels 0:1193dbfe28e2 120 #define PARMSET_Slew1p65Vus 0x04
pwheels 0:1193dbfe28e2 121 #define PARMSET_Slew1p37Vus 0x06
pwheels 0:1193dbfe28e2 122 #define PARMSET_Slew1p1Vus 0x08
pwheels 0:1193dbfe28e2 123 #define PARMSET_Slew0p83Vus 0x0A
pwheels 0:1193dbfe28e2 124 #define PARMSET_Slew0p7Vus 0x0C
pwheels 0:1193dbfe28e2 125 #define PARMSET_Slew0p55Vus 0x0E
pwheels 0:1193dbfe28e2 126
pwheels 0:1193dbfe28e2 127 // 12V programming pulse time table
pwheels 0:1193dbfe28e2 128 #define PARMSET_32us 0x00
pwheels 0:1193dbfe28e2 129 #define PARMSET_64us 0x02
pwheels 0:1193dbfe28e2 130 #define PARMSET_128us 0x04
pwheels 0:1193dbfe28e2 131 #define PARMSET_256us 0x06
pwheels 0:1193dbfe28e2 132 #define PARMSET_512us 0x08
pwheels 0:1193dbfe28e2 133 #define PARMSET_1024us 0x0A
pwheels 0:1193dbfe28e2 134 #define PARMSET_2048us 0x0C
pwheels 0:1193dbfe28e2 135 #define PARMSET_infinite 0x0E
pwheels 0:1193dbfe28e2 136
pwheels 0:1193dbfe28e2 137 // 5V strong pull up pulse time table
pwheels 0:1193dbfe28e2 138 #define PARMSET_16p4ms 0x00
pwheels 0:1193dbfe28e2 139 #define PARMSET_65p5ms 0x02
pwheels 0:1193dbfe28e2 140 #define PARMSET_131ms 0x04
pwheels 0:1193dbfe28e2 141 #define PARMSET_262ms 0x06
pwheels 0:1193dbfe28e2 142 #define PARMSET_524ms 0x08
pwheels 0:1193dbfe28e2 143 #define PARMSET_1p05s 0x0A
pwheels 0:1193dbfe28e2 144 #define PARMSET_2p10s 0x0C
pwheels 0:1193dbfe28e2 145 #define PARMSET_infinite 0x0E
pwheels 0:1193dbfe28e2 146
pwheels 0:1193dbfe28e2 147 // Write 1 low time
pwheels 0:1193dbfe28e2 148 #define PARMSET_Write8us 0x00
pwheels 0:1193dbfe28e2 149 #define PARMSET_Write9us 0x02
pwheels 0:1193dbfe28e2 150 #define PARMSET_Write10us 0x04
pwheels 0:1193dbfe28e2 151 #define PARMSET_Write11us 0x06
pwheels 0:1193dbfe28e2 152 #define PARMSET_Write12us 0x08
pwheels 0:1193dbfe28e2 153 #define PARMSET_Write13us 0x0A
pwheels 0:1193dbfe28e2 154 #define PARMSET_Write14us 0x0C
pwheels 0:1193dbfe28e2 155 #define PARMSET_Write15us 0x0E
pwheels 0:1193dbfe28e2 156
pwheels 0:1193dbfe28e2 157 // Data sample offset and Write 0 recovery time
pwheels 0:1193dbfe28e2 158 #define PARMSET_SampOff3us 0x00
pwheels 0:1193dbfe28e2 159 #define PARMSET_SampOff4us 0x02
pwheels 0:1193dbfe28e2 160 #define PARMSET_SampOff5us 0x04
pwheels 0:1193dbfe28e2 161 #define PARMSET_SampOff6us 0x06
pwheels 0:1193dbfe28e2 162 #define PARMSET_SampOff7us 0x08
pwheels 0:1193dbfe28e2 163 #define PARMSET_SampOff8us 0x0A
pwheels 0:1193dbfe28e2 164 #define PARMSET_SampOff9us 0x0C
pwheels 0:1193dbfe28e2 165 #define PARMSET_SampOff10us 0x0E
pwheels 0:1193dbfe28e2 166
pwheels 0:1193dbfe28e2 167 // Active pull up on time
pwheels 0:1193dbfe28e2 168 #define PARMSET_PullUp0p0us 0x00
pwheels 0:1193dbfe28e2 169 #define PARMSET_PullUp0p5us 0x02
pwheels 0:1193dbfe28e2 170 #define PARMSET_PullUp1p0us 0x04
pwheels 0:1193dbfe28e2 171 #define PARMSET_PullUp1p5us 0x06
pwheels 0:1193dbfe28e2 172 #define PARMSET_PullUp2p0us 0x08
pwheels 0:1193dbfe28e2 173 #define PARMSET_PullUp2p5us 0x0A
pwheels 0:1193dbfe28e2 174 #define PARMSET_PullUp3p0us 0x0C
pwheels 0:1193dbfe28e2 175 #define PARMSET_PullUp3p5us 0x0E
pwheels 0:1193dbfe28e2 176
pwheels 0:1193dbfe28e2 177 // Baud rate bits
pwheels 0:1193dbfe28e2 178 #define PARMSET_9600 0x00
pwheels 0:1193dbfe28e2 179 #define PARMSET_19200 0x02
pwheels 0:1193dbfe28e2 180 #define PARMSET_57600 0x04
pwheels 0:1193dbfe28e2 181 #define PARMSET_115200 0x06
pwheels 0:1193dbfe28e2 182
pwheels 0:1193dbfe28e2 183 // Baud rate bits - Inverted Read
pwheels 0:1193dbfe28e2 184 #define PARMSET_INV_9600 0x08
pwheels 0:1193dbfe28e2 185 #define PARMSET_INV_19200 0x0A
pwheels 0:1193dbfe28e2 186 #define PARMSET_INV_57600 0x0C
pwheels 0:1193dbfe28e2 187 #define PARMSET_INV_115200 0x0E
pwheels 0:1193dbfe28e2 188
pwheels 0:1193dbfe28e2 189
pwheels 0:1193dbfe28e2 190 // DS2480B program voltage available
pwheels 0:1193dbfe28e2 191 #define DS2480PROG_MASK 0x20
pwheels 0:1193dbfe28e2 192
pwheels 0:1193dbfe28e2 193 // mode bit flags
pwheels 0:1193dbfe28e2 194 #define MODE_NORMAL 0x00
pwheels 0:1193dbfe28e2 195 #define MODE_OVERDRIVE 0x01
pwheels 0:1193dbfe28e2 196 #define MODE_STRONG5 0x02
pwheels 0:1193dbfe28e2 197 #define MODE_PROGRAM 0x04
pwheels 0:1193dbfe28e2 198 #define MODE_BREAK 0x08
pwheels 0:1193dbfe28e2 199
pwheels 0:1193dbfe28e2 200 // Versions of DS2480
pwheels 0:1193dbfe28e2 201 #define VER_LINK 0x1C
pwheels 0:1193dbfe28e2 202 #define VER_DS2480 0x08
pwheels 0:1193dbfe28e2 203 #define VER_DS2480B 0x0C
pwheels 0:1193dbfe28e2 204
pwheels 0:1193dbfe28e2 205 // exportable functions defined in ds2480ut.c
pwheels 0:1193dbfe28e2 206 SMALLINT DS2480Detect(int portnum);
pwheels 0:1193dbfe28e2 207 SMALLINT DS2480ChangeBaud(int portnum, uchar newbaud);
pwheels 0:1193dbfe28e2 208
pwheels 0:1193dbfe28e2 209 // link functions from win32lnk.c or other link files
pwheels 0:1193dbfe28e2 210 SMALLINT OpenCOM(int portnum, char *port_zstr);
pwheels 0:1193dbfe28e2 211 int OpenCOMEx(char *port_zstr);
pwheels 0:1193dbfe28e2 212 void CloseCOM(int portnum);
pwheels 0:1193dbfe28e2 213 void FlushCOM(int portnum);
pwheels 0:1193dbfe28e2 214 SMALLINT WriteCOM(int portnum, int outlen, uchar *outbuf);
pwheels 0:1193dbfe28e2 215 int ReadCOM(int portnum, int inlen, uchar *inbuf);
pwheels 0:1193dbfe28e2 216 void BreakCOM(int portnum);
pwheels 0:1193dbfe28e2 217 void SetBaudCOM(int portnum, int new_baud);
pwheels 0:1193dbfe28e2 218
pwheels 0:1193dbfe28e2 219
pwheels 0:1193dbfe28e2 220 #endif //DS2480_H