1 //---------------------------------------------------------------------------
2 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
18 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 // OTHER DEALINGS IN THE SOFTWARE.
22 // Except as contained in this notice, the name of Dallas Semiconductor
23 // shall not be used except as stated in the Dallas Semiconductor
25 //--------------------------------------------------------------------------
27 // ad26.c - Reads the voltage on the 1-Wire
36 int Volt_AD(int portnum, int vdd, uchar *SNum)
45 owSerialNum(portnum,SNum,FALSE);
46 // Recall the Status/Configuration page
48 send_block[send_cnt++] = 0xB8;
51 send_block[send_cnt++] = 0x00;
53 if(!owBlock(portnum,FALSE,send_block,send_cnt))
60 // Read the Status/Configuration byte
61 // Read scratchpad command
62 send_block[send_cnt++] = 0xBE;
64 // Page for the Status/Configuration byte
65 send_block[send_cnt++] = 0x00;
68 send_block[send_cnt++] = 0xFF;
70 if(owBlock(portnum,FALSE,send_block,send_cnt))
74 for(i=2;i<send_cnt;i++)
75 lastcrc8 = docrc8(portnum,send_block[i]);
83 test = send_block[2] & 0x08;
84 if(((test == 0x08) && vdd) || ((test == 0x00) && !(vdd)))
91 // Write the Status/Configuration byte
92 // Write scratchpad command
93 send_block[send_cnt++] = 0x4E;
96 send_block[send_cnt++] = 0x00;
99 send_block[send_cnt++] = send_block[2] | 0x08;
101 send_block[send_cnt++] = send_block[2] & 0xF7;
104 send_block[send_cnt++] = send_block[i+4];
106 if(owBlock(portnum,FALSE,send_block,send_cnt))
110 if(owAccess(portnum))
112 // Copy the Status/Configuration byte
113 // Copy scratchpad command
114 send_block[send_cnt++] = 0x48;
117 send_block[send_cnt++] = 0x00;
119 if(owBlock(portnum,FALSE,send_block,send_cnt))
121 busybyte = owReadByte(portnum);
124 busybyte = owReadByte(portnum);
137 float Volt_Reading(int portnum, int vdd, uchar *SNum)
139 uchar send_block[50];
147 if(Volt_AD(portnum,vdd,SNum))
150 if(owAccess(portnum))
152 if(!owWriteByte(portnum,0xB4))
154 //output_status(LV_ALWAYS,(char *)"DIDN'T WRITE CORRECTLY\n");
155 printf ("DIDN'T WRITE CORRECTLY\n");
159 busybyte = owReadByte(portnum);
162 busybyte = owReadByte(portnum);
165 if(owAccess(portnum))
167 // Recall the Status/Configuration page
169 send_block[send_cnt++] = 0xB8;
172 send_block[send_cnt++] = 0x00;
174 if(!owBlock(portnum,FALSE,send_block,send_cnt))
181 if(owAccess(portnum))
183 // Read the Status/Configuration byte
184 // Read scratchpad command
185 send_block[send_cnt++] = 0xBE;
187 // Page for the Status/Configuration byte
188 send_block[send_cnt++] = 0x00;
191 send_block[send_cnt++] = 0xFF;
193 if(owBlock(portnum,FALSE,send_block,send_cnt))
197 for(i=2;i<send_cnt;i++)
198 lastcrc8 = docrc8(portnum,send_block[i]);
207 volts = ((int)send_block[6] << 8) | send_block[5];
208 ret = (float) volts/100;
216 double Get_Temperature(int portnum,uchar *SNum)
219 uchar send_block[50];
224 owSerialNum(portnum,SNum,FALSE);
226 if(owAccess(portnum))
227 // Convert Temperature command
228 owWriteByte(portnum,0x44);
233 if(owAccess(portnum))
235 // Read the Status/Configuration byte
236 // Read scratchpad command
237 send_block[send_cnt++] = 0xBE;
239 // Page for the Status/Configuration byte
240 send_block[send_cnt++] = 0x00;
243 send_block[send_cnt++] = 0xFF;
245 if(owBlock(portnum,FALSE,send_block,send_cnt))
249 for(i=2;i<send_cnt;i++) {
250 lastcrc8 = docrc8(portnum,send_block[i]);
260 ret = ((((unsigned int)send_block[4] << 8) | send_block[3]) >> 3) * 0.03125;