Now supports DS18B20 and DS18S20 Maxim/Dallas one-wire thermometer devices. Also supports DS18S20 in 9, 10, 11, and 12 bit resolution modes. 'Use Address' mode now checks if the correct device type is present, and informs the user which device to use. Correct temperature conversion times now used in non-parasitic mode. The device should be placed at least 6 inches (15 cm) from the mbed board in order to accurately read ambient temperature.

Dependencies:   mbed

Fork of OneWireCRC by Petras Saduikis

Committer:
lagish
Date:
Mon Jul 13 17:22:49 2015 +0000
Revision:
1:ade3fad22621
Parent:
0:01a6a40578c9
Draft1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
snatch59 0:01a6a40578c9 1 /*
snatch59 0:01a6a40578c9 2 * OneWireCRC/OneWireThermometer demo.
snatch59 0:01a6a40578c9 3 *
snatch59 0:01a6a40578c9 4 * Copyright (C) <2009> Petras Saduikis <petras@petras.co.uk>
snatch59 0:01a6a40578c9 5 *
snatch59 0:01a6a40578c9 6 * This file is part of OneWireCRC/OneWireThermometer.
snatch59 0:01a6a40578c9 7 *
snatch59 0:01a6a40578c9 8 * OneWireCRC/OneWireThermometer is free software: you can redistribute it and/or modify
snatch59 0:01a6a40578c9 9 * it under the terms of the GNU General Public License as published by
snatch59 0:01a6a40578c9 10 * the Free Software Foundation, either version 3 of the License, or
snatch59 0:01a6a40578c9 11 * (at your option) any later version.
snatch59 0:01a6a40578c9 12 *
snatch59 0:01a6a40578c9 13 * OneWireCRC/OneWireThermometer is distributed in the hope that it will be useful,
snatch59 0:01a6a40578c9 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
snatch59 0:01a6a40578c9 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
snatch59 0:01a6a40578c9 16 * GNU General Public License for more details.
snatch59 0:01a6a40578c9 17 *
snatch59 0:01a6a40578c9 18 * You should have received a copy of the GNU General Public License
snatch59 0:01a6a40578c9 19 * along with OneWireCRC/OneWireThermometer0. If not, see <http://www.gnu.org/licenses/>.
snatch59 0:01a6a40578c9 20 */
snatch59 0:01a6a40578c9 21
snatch59 0:01a6a40578c9 22 ////////////////////////////////////////////////////////////////////
snatch59 0:01a6a40578c9 23 // Test code to read temperature from a Maxim DS18B20 or DS18S20
snatch59 0:01a6a40578c9 24 // 1-wire device
snatch59 0:01a6a40578c9 25 ////////////////////////////////////////////////////////////////////
snatch59 0:01a6a40578c9 26
snatch59 0:01a6a40578c9 27 #include <mbed.h>
snatch59 0:01a6a40578c9 28 #include "DS18S20.h"
snatch59 0:01a6a40578c9 29 #include "DS18B20.h"
snatch59 0:01a6a40578c9 30 #include "OneWireDefs.h"
snatch59 0:01a6a40578c9 31
lagish 1:ade3fad22621 32 DigitalOut myled(LED1);
lagish 1:ade3fad22621 33
snatch59 0:01a6a40578c9 34 //#define THERMOMETER DS18S20
snatch59 0:01a6a40578c9 35 #define THERMOMETER DS18B20
snatch59 0:01a6a40578c9 36
snatch59 0:01a6a40578c9 37 int main()
snatch59 0:01a6a40578c9 38 {
snatch59 0:01a6a40578c9 39 // device( crcOn, useAddress, parasitic, mbed pin )
snatch59 0:01a6a40578c9 40 THERMOMETER device(true, true, false, p25);
snatch59 0:01a6a40578c9 41
snatch59 0:01a6a40578c9 42 while (!device.initialize()); // keep calling until it works
lagish 1:ade3fad22621 43
snatch59 0:01a6a40578c9 44 while (true)
snatch59 0:01a6a40578c9 45 {
snatch59 0:01a6a40578c9 46 // changing the resolutions only affects the DS18B20. The DS18S20 is fixed.
snatch59 0:01a6a40578c9 47 device.setResolution(nineBit);
snatch59 0:01a6a40578c9 48 device.readTemperature();
lagish 1:ade3fad22621 49 myled=1;
snatch59 0:01a6a40578c9 50 wait(2);
snatch59 0:01a6a40578c9 51 device.setResolution(tenBit);
snatch59 0:01a6a40578c9 52 device.readTemperature();
lagish 1:ade3fad22621 53 myled=0;
snatch59 0:01a6a40578c9 54 wait(2);
snatch59 0:01a6a40578c9 55 device.setResolution(elevenBit);
snatch59 0:01a6a40578c9 56 device.readTemperature();
lagish 1:ade3fad22621 57 myled=1;
snatch59 0:01a6a40578c9 58 wait(2);
snatch59 0:01a6a40578c9 59 device.setResolution(twelveBit);
snatch59 0:01a6a40578c9 60 device.readTemperature();
lagish 1:ade3fad22621 61 myled=0;
snatch59 0:01a6a40578c9 62 wait(2);
snatch59 0:01a6a40578c9 63 }
snatch59 0:01a6a40578c9 64
snatch59 0:01a6a40578c9 65 return EXIT_SUCCESS;
snatch59 0:01a6a40578c9 66 }