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 // findtype.c - Test module to find all devices of one type.
pwheels 0:1193dbfe28e2 28 //
pwheels 0:1193dbfe28e2 29 // Version: 2.00
pwheels 0:1193dbfe28e2 30 //
pwheels 0:1193dbfe28e2 31 //----------------------------------------------------------------------
pwheels 0:1193dbfe28e2 32 //
pwheels 0:1193dbfe28e2 33 //
pwheels 0:1193dbfe28e2 34 #include "ownet.h"
pwheels 0:1193dbfe28e2 35 #include "./Headers/findtype.h"
pwheels 0:1193dbfe28e2 36
pwheels 0:1193dbfe28e2 37 //----------------------------------------------------------------------
pwheels 0:1193dbfe28e2 38 // Search for devices
pwheels 0:1193dbfe28e2 39 //
pwheels 0:1193dbfe28e2 40 // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
pwheels 0:1193dbfe28e2 41 // indicate the symbolic port number.
pwheels 0:1193dbfe28e2 42 // 'FamilySN' - an array of all the serial numbers with the matching
pwheels 0:1193dbfe28e2 43 // family code
pwheels 0:1193dbfe28e2 44 // 'family_code' - the family code of the devices to search for on the
pwheels 0:1193dbfe28e2 45 // 1-Wire Net
pwheels 0:1193dbfe28e2 46 // 'MAXDEVICES' - the maximum number of devices to look for with the
pwheels 0:1193dbfe28e2 47 // family code passed.
pwheels 0:1193dbfe28e2 48 //
pwheels 0:1193dbfe28e2 49 // Returns: TRUE(1) success, device type found
pwheels 0:1193dbfe28e2 50 // FALSE(0) device not found
pwheels 0:1193dbfe28e2 51 //
pwheels 0:1193dbfe28e2 52 SMALLINT FindDevices(int portnum, uchar FamilySN[][8], SMALLINT family_code, int MAXDEVICES)
pwheels 0:1193dbfe28e2 53 {
pwheels 0:1193dbfe28e2 54 int NumDevices=0;
pwheels 0:1193dbfe28e2 55
pwheels 0:1193dbfe28e2 56 // find the devices
pwheels 0:1193dbfe28e2 57 // set the search to first find that family code
pwheels 0:1193dbfe28e2 58 owFamilySearchSetup(portnum,family_code);
pwheels 0:1193dbfe28e2 59
pwheels 0:1193dbfe28e2 60 // loop to find all of the devices up to MAXDEVICES
pwheels 0:1193dbfe28e2 61 NumDevices = 0;
pwheels 0:1193dbfe28e2 62 do
pwheels 0:1193dbfe28e2 63 {
pwheels 0:1193dbfe28e2 64 // perform the search
pwheels 0:1193dbfe28e2 65 if (!owNext(portnum,TRUE, FALSE))
pwheels 0:1193dbfe28e2 66 break;
pwheels 0:1193dbfe28e2 67
pwheels 0:1193dbfe28e2 68 owSerialNum(portnum,FamilySN[NumDevices], TRUE);
pwheels 0:1193dbfe28e2 69 if ((FamilySN[NumDevices][0] & 0x7F) == (family_code & 0x7F))
pwheels 0:1193dbfe28e2 70 {
pwheels 0:1193dbfe28e2 71 NumDevices++;
pwheels 0:1193dbfe28e2 72 }
pwheels 0:1193dbfe28e2 73 }
pwheels 0:1193dbfe28e2 74 while (NumDevices < (MAXDEVICES - 1));
pwheels 0:1193dbfe28e2 75
pwheels 0:1193dbfe28e2 76 // check if not at least 1 device
pwheels 0:1193dbfe28e2 77 return NumDevices;
pwheels 0:1193dbfe28e2 78 }