Program to read the temperature from multiple DS18B20 sensors on the same pin. The original library/code came from Petras Saduikis (see http://mbed.org/users/snatch59/programs/OneWireCRC/gpdz56), but I've modified it to remember the address of multiple sensors all connected to the same data pin. My sample program displays the temperature of each device in turn. If you want to see more of what's going on behind the scenes turn on the debug by setting DebugTrace pc(OFF, TO_SERIAL); to ON (instead of OFF) in the couple of places it's used - it will log the device addresses as they are found etc. The addresses are set in the devices at the factory - I don't think they can be changed, the search always seems to find them in the same order, but this won't be anything to do with the way you've plugged them in. I've had a play with up to 7 sensors (the code has a limit of 10 hardwired in it, but this would be easy to change)

Dependencies:   mbed

Committer:
tonymudd
Date:
Sun Jul 17 15:56:49 2011 +0000
Revision:
0:fb8b6da96a8b

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tonymudd 0:fb8b6da96a8b 1 /*
tonymudd 0:fb8b6da96a8b 2 * OneWireCRC. This is a port to mbed of Jim Studt's Adruino One Wire
tonymudd 0:fb8b6da96a8b 3 * library.
tonymudd 0:fb8b6da96a8b 4 *
tonymudd 0:fb8b6da96a8b 5 * Copyright (C) <2009> Petras Saduikis <petras@petras.co.uk>
tonymudd 0:fb8b6da96a8b 6 *
tonymudd 0:fb8b6da96a8b 7 * This file is part of OneWireCRC.
tonymudd 0:fb8b6da96a8b 8 *
tonymudd 0:fb8b6da96a8b 9 * OneWireCRC is free software: you can redistribute it and/or modify
tonymudd 0:fb8b6da96a8b 10 * it under the terms of the GNU General Public License as published by
tonymudd 0:fb8b6da96a8b 11 * the Free Software Foundation, either version 3 of the License, or
tonymudd 0:fb8b6da96a8b 12 * (at your option) any later version.
tonymudd 0:fb8b6da96a8b 13 *
tonymudd 0:fb8b6da96a8b 14 * OneWireCRC is distributed in the hope that it will be useful,
tonymudd 0:fb8b6da96a8b 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
tonymudd 0:fb8b6da96a8b 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
tonymudd 0:fb8b6da96a8b 17 * GNU General Public License for more details.
tonymudd 0:fb8b6da96a8b 18 *
tonymudd 0:fb8b6da96a8b 19 * You should have received a copy of the GNU General Public License
tonymudd 0:fb8b6da96a8b 20 * along with OneWireCRC. If not, see <http://www.gnu.org/licenses/>.
tonymudd 0:fb8b6da96a8b 21 */
tonymudd 0:fb8b6da96a8b 22
tonymudd 0:fb8b6da96a8b 23 #ifndef SNATCH59_ONEWIREDEFS_H
tonymudd 0:fb8b6da96a8b 24 #define SNATCH59_ONEWIREDEFS_H
tonymudd 0:fb8b6da96a8b 25
tonymudd 0:fb8b6da96a8b 26 // device ids
tonymudd 0:fb8b6da96a8b 27 #define DS18B20_ID 0x28
tonymudd 0:fb8b6da96a8b 28 #define DS18S20_ID 0x10
tonymudd 0:fb8b6da96a8b 29
tonymudd 0:fb8b6da96a8b 30 #define ALARM_CONFIG_SIZE 3
tonymudd 0:fb8b6da96a8b 31 #define THERMOM_SCRATCHPAD_SIZE 9
tonymudd 0:fb8b6da96a8b 32 #define THERMOM_CRC_BYTE 8
tonymudd 0:fb8b6da96a8b 33 #define ADDRESS_SIZE 8
tonymudd 0:fb8b6da96a8b 34 #define ADDRESS_CRC_BYTE 7
tonymudd 0:fb8b6da96a8b 35
tonymudd 0:fb8b6da96a8b 36 // One Wire command codes
tonymudd 0:fb8b6da96a8b 37 #define OVERDRIVE_SKIP 0x3C
tonymudd 0:fb8b6da96a8b 38 // ROM commands
tonymudd 0:fb8b6da96a8b 39 #define SEARCH_ROM 0xF0
tonymudd 0:fb8b6da96a8b 40 #define READ_ROM 0x33
tonymudd 0:fb8b6da96a8b 41 #define MATCH_ROM 0x55
tonymudd 0:fb8b6da96a8b 42 #define SKIP_ROM 0xCC
tonymudd 0:fb8b6da96a8b 43 #define ALARM_SEARCH 0xEC
tonymudd 0:fb8b6da96a8b 44 // Functions Commnds
tonymudd 0:fb8b6da96a8b 45 #define CONVERT 0x44
tonymudd 0:fb8b6da96a8b 46 #define WRITESCRATCH 0x4E
tonymudd 0:fb8b6da96a8b 47 #define READSCRATCH 0xBE
tonymudd 0:fb8b6da96a8b 48 #define COPYSCRATCH 0x48
tonymudd 0:fb8b6da96a8b 49 #define RECALLE2 0xB8
tonymudd 0:fb8b6da96a8b 50 #define READPOWERSUPPLY 0xB4
tonymudd 0:fb8b6da96a8b 51
tonymudd 0:fb8b6da96a8b 52 // temperature read resolutions
tonymudd 0:fb8b6da96a8b 53 enum eResolution {nineBit = 0, tenBit, elevenBit, twelveBit};
tonymudd 0:fb8b6da96a8b 54 const int CONVERSION_TIME[] = {94, 188, 375, 750}; // milli-seconds
tonymudd 0:fb8b6da96a8b 55
tonymudd 0:fb8b6da96a8b 56 // DS18B20/DS18S20 related
tonymudd 0:fb8b6da96a8b 57 #define TEMPERATURE_LSB 0
tonymudd 0:fb8b6da96a8b 58 #define TEMPERATURE_MSB 1
tonymudd 0:fb8b6da96a8b 59 #define HIGH_ALARM_BYTE 2
tonymudd 0:fb8b6da96a8b 60 #define LOW_ALARM_BYTE 3
tonymudd 0:fb8b6da96a8b 61 #define CONFIG_REG_BYTE 4
tonymudd 0:fb8b6da96a8b 62 #define CONFIG_READ_END 5
tonymudd 0:fb8b6da96a8b 63 #define COUNT_REMAIN_BYTE 6
tonymudd 0:fb8b6da96a8b 64 #define COUNT_PER_DEG_BYTE 7
tonymudd 0:fb8b6da96a8b 65
tonymudd 0:fb8b6da96a8b 66 #endif