Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: CUER_CAN CUER_DS1820 LTC2943 LTC6804 mbed PowerControl
Temperature.cpp@38:b1f5bfe38d70, 2017-07-22 (annotated)
- Committer:
- DasSidG
- Date:
- Sat Jul 22 11:11:53 2017 +0000
- Revision:
- 38:b1f5bfe38d70
- Parent:
- 21:d461d58e70fc
- Child:
- 66:c884fba9eaea
Made it so that temperature measurements don't happen every loop
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lcockerton62 | 1:51477fe4851b | 1 | /* |
lcockerton62 | 1:51477fe4851b | 2 | * Code for identifying address and temperature of DS1820 1-Wire Thermometers by Maxim |
lcockerton62 | 1:51477fe4851b | 3 | * Uses the DS1820 library written by Michael Hagberg and Fernando Caamaño, with some slight modifications |
lcockerton62 | 1:51477fe4851b | 4 | * Currently tested using DS18S20 1-Wire Thermometers in an array, parasite power yet to be tested |
lcockerton62 | 1:51477fe4851b | 5 | */ |
lcockerton62 | 1:51477fe4851b | 6 | #include "Temperature.h" |
DasSidG | 38:b1f5bfe38d70 | 7 | #define DEBUG 0 |
lcockerton62 | 1:51477fe4851b | 8 | |
lcockerton62 | 1:51477fe4851b | 9 | DS1820* probe[MAX_PROBES]; |
maxv008 | 18:521ffdd724f3 | 10 | int devices_found; |
DasSidG | 21:d461d58e70fc | 11 | DigitalOut isotherm_12V_pin(ISOTHERM_12V_PIN); |
lcockerton62 | 1:51477fe4851b | 12 | |
lcockerton62 | 1:51477fe4851b | 13 | void temperature_init() |
lcockerton62 | 1:51477fe4851b | 14 | { |
maxv008 | 20:a1a1bfc938da | 15 | //DigitalOut isotherm_12V_pin(ISOTHERM_12V_PIN); |
DasSidG | 21:d461d58e70fc | 16 | isotherm_12V_pin = 1; |
lcockerton62 | 1:51477fe4851b | 17 | int address_byte_count; |
lcockerton62 | 1:51477fe4851b | 18 | // Initialize the probe array to DS1820 objects |
DasSidG | 21:d461d58e70fc | 19 | for (int i = 0; i < MAX_PROBES; i++) |
lcockerton62 | 1:51477fe4851b | 20 | probe[i] = new DS1820(DATA_PIN, PARASITE_PIN); |
lcockerton62 | 1:51477fe4851b | 21 | // Initialize global state variables |
lcockerton62 | 1:51477fe4851b | 22 | probe[0]->search_ROM_setup(); |
lcockerton62 | 1:51477fe4851b | 23 | // Loop to find all devices on the data line |
lcockerton62 | 1:51477fe4851b | 24 | while (probe[devices_found]->search_ROM() and devices_found<MAX_PROBES-1) |
lcockerton62 | 1:51477fe4851b | 25 | devices_found++; |
DasSidG | 21:d461d58e70fc | 26 | |
DasSidG | 21:d461d58e70fc | 27 | isotherm_12V_pin = 0; |
lcockerton62 | 1:51477fe4851b | 28 | // If maximum number of probes are found, |
lcockerton62 | 1:51477fe4851b | 29 | // bump the counter to include the last array entry |
lcockerton62 | 1:51477fe4851b | 30 | if (probe[devices_found]->ROM[0] != 0xFF) |
lcockerton62 | 1:51477fe4851b | 31 | devices_found++; |
lcockerton62 | 1:51477fe4851b | 32 | |
lcockerton62 | 1:51477fe4851b | 33 | if (devices_found==0) |
DasSidG | 38:b1f5bfe38d70 | 34 | if (DEBUG) printf("No devices found"); |
lcockerton62 | 1:51477fe4851b | 35 | else { |
DasSidG | 38:b1f5bfe38d70 | 36 | if (DEBUG) printf("\n%d device(s) found!\r\n\n" ,devices_found); |
DasSidG | 21:d461d58e70fc | 37 | for (int i=0; i<devices_found; i++) { |
DasSidG | 38:b1f5bfe38d70 | 38 | if (DEBUG) printf("Device %d address is: \r\n", i+1); |
lcockerton62 | 1:51477fe4851b | 39 | for(address_byte_count=0; address_byte_count<8; address_byte_count++) { |
DasSidG | 38:b1f5bfe38d70 | 40 | if (DEBUG) printf("0x%02x", probe[i]->ROM[address_byte_count]); |
DasSidG | 38:b1f5bfe38d70 | 41 | if(address_byte_count == 7) { |
DasSidG | 38:b1f5bfe38d70 | 42 | if (DEBUG) printf("\r\n\n"); |
DasSidG | 38:b1f5bfe38d70 | 43 | } |
lcockerton62 | 1:51477fe4851b | 44 | else printf(", "); |
lcockerton62 | 1:51477fe4851b | 45 | } |
lcockerton62 | 1:51477fe4851b | 46 | } |
lcockerton62 | 1:51477fe4851b | 47 | } |
lcockerton62 | 1:51477fe4851b | 48 | } |
lcockerton62 | 1:51477fe4851b | 49 |