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 // owSesU.C - Acquire and release a Session on the 1-Wire Net.
pwheels 0:1193dbfe28e2 28 //
pwheels 0:1193dbfe28e2 29 // Version: 2.01
pwheels 0:1193dbfe28e2 30 //
pwheels 0:1193dbfe28e2 31 // History: 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for
pwheels 0:1193dbfe28e2 32 // multiple ports.
pwheels 0:1193dbfe28e2 33 // 2.00 -> 2.01 Added error handling. Added circular-include check.
pwheels 0:1193dbfe28e2 34 // 2.01 -> 2.10 Added raw memory error handling and SMALLINT
pwheels 0:1193dbfe28e2 35 // 2.10 -> 3.00 Added memory bank functionality
pwheels 0:1193dbfe28e2 36 // Added file I/O operations
pwheels 0:1193dbfe28e2 37 //
pwheels 0:1193dbfe28e2 38
pwheels 0:1193dbfe28e2 39 #include "mbed.h"
pwheels 0:1193dbfe28e2 40 #include "ownet.h"
pwheels 0:1193dbfe28e2 41 #include "./Headers/ds2480.h"
pwheels 0:1193dbfe28e2 42
pwheels 0:1193dbfe28e2 43 //---------------------------------------------------------------------------
pwheels 0:1193dbfe28e2 44 // Attempt to acquire a 1-Wire net using a com port and a DS2480 based
pwheels 0:1193dbfe28e2 45 // adapter.
pwheels 0:1193dbfe28e2 46 //
pwheels 0:1193dbfe28e2 47 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
pwheels 0:1193dbfe28e2 48 // OpenCOM to indicate the port number.
pwheels 0:1193dbfe28e2 49 // 'port_zstr' - zero terminated port name. For this platform
pwheels 0:1193dbfe28e2 50 // use format COMX where X is the port number.
pwheels 0:1193dbfe28e2 51 //
pwheels 0:1193dbfe28e2 52 // Returns: TRUE - success, COM port opened
pwheels 0:1193dbfe28e2 53 //
pwheels 0:1193dbfe28e2 54 // exportable functions defined in ownetu.c
pwheels 0:1193dbfe28e2 55 SMALLINT owAcquire(int portnum, char *port_zstr)
pwheels 0:1193dbfe28e2 56 {
pwheels 0:1193dbfe28e2 57 // attempt to open the communications port
pwheels 0:1193dbfe28e2 58 if (OpenCOM(portnum,port_zstr) < 0)
pwheels 0:1193dbfe28e2 59 {
pwheels 0:1193dbfe28e2 60 OWERROR(OWERROR_OPENCOM_FAILED);
pwheels 0:1193dbfe28e2 61 return FALSE;
pwheels 0:1193dbfe28e2 62 }
pwheels 0:1193dbfe28e2 63
pwheels 0:1193dbfe28e2 64 // detect DS2480
pwheels 0:1193dbfe28e2 65 if (!DS2480Detect(portnum))
pwheels 0:1193dbfe28e2 66 {
pwheels 0:1193dbfe28e2 67 CloseCOM(portnum);
pwheels 0:1193dbfe28e2 68 OWERROR(OWERROR_DS2480_NOT_DETECTED);
pwheels 0:1193dbfe28e2 69 return FALSE;
pwheels 0:1193dbfe28e2 70 }
pwheels 0:1193dbfe28e2 71
pwheels 0:1193dbfe28e2 72 return TRUE;
pwheels 0:1193dbfe28e2 73 }
pwheels 0:1193dbfe28e2 74
pwheels 0:1193dbfe28e2 75 //---------------------------------------------------------------------------
pwheels 0:1193dbfe28e2 76 // Attempt to acquire a 1-Wire net using a com port and a DS2480 based
pwheels 0:1193dbfe28e2 77 // adapter.
pwheels 0:1193dbfe28e2 78 //
pwheels 0:1193dbfe28e2 79 // 'port_zstr' - zero terminated port name. For this platform
pwheels 0:1193dbfe28e2 80 // use format COMX where X is the port number.
pwheels 0:1193dbfe28e2 81 //
pwheels 0:1193dbfe28e2 82 // Returns: valid handle, or -1 if an error occurred
pwheels 0:1193dbfe28e2 83 //
pwheels 0:1193dbfe28e2 84 // exportable functions defined in ownetu.c
pwheels 0:1193dbfe28e2 85 //
pwheels 0:1193dbfe28e2 86 int owAcquireEx(char *port_zstr)
pwheels 0:1193dbfe28e2 87 {
pwheels 0:1193dbfe28e2 88 int portnum;
pwheels 0:1193dbfe28e2 89
pwheels 0:1193dbfe28e2 90 // attempt to open the communications port
pwheels 0:1193dbfe28e2 91 if ((portnum = OpenCOMEx(port_zstr)) < 0)
pwheels 0:1193dbfe28e2 92 {
pwheels 0:1193dbfe28e2 93 OWERROR(OWERROR_OPENCOM_FAILED);
pwheels 0:1193dbfe28e2 94 return -1;
pwheels 0:1193dbfe28e2 95 }
pwheels 0:1193dbfe28e2 96
pwheels 0:1193dbfe28e2 97 // detect DS2480
pwheels 0:1193dbfe28e2 98 if (!DS2480Detect(portnum))
pwheels 0:1193dbfe28e2 99 {
pwheels 0:1193dbfe28e2 100 CloseCOM(portnum);
pwheels 0:1193dbfe28e2 101 OWERROR(OWERROR_DS2480_NOT_DETECTED);
pwheels 0:1193dbfe28e2 102 return -1;
pwheels 0:1193dbfe28e2 103 }
pwheels 0:1193dbfe28e2 104
pwheels 0:1193dbfe28e2 105 return portnum;
pwheels 0:1193dbfe28e2 106 }
pwheels 0:1193dbfe28e2 107
pwheels 0:1193dbfe28e2 108 //---------------------------------------------------------------------------
pwheels 0:1193dbfe28e2 109 // Release the previously acquired a 1-Wire net.
pwheels 0:1193dbfe28e2 110 //
pwheels 0:1193dbfe28e2 111 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
pwheels 0:1193dbfe28e2 112 // OpenCOM to indicate the port number.
pwheels 0:1193dbfe28e2 113 //
pwheels 0:1193dbfe28e2 114 void owRelease(int portnum)
pwheels 0:1193dbfe28e2 115 {
pwheels 0:1193dbfe28e2 116 CloseCOM(portnum);
pwheels 0:1193dbfe28e2 117 }