// Demo on how to identify and read multiple DS18B20 connected to the same bus. // Parasitic power is not used in this example. // This program is based on the sample code from Maxim/Dallas application // note 162 (http://www.maxim-ic.com/app-notes/index.mvp/id/162). Program output should look like this: *** Test with multiple DS18B20 *** Memory allocated for 20 devices. Scanning for devices... ROM CODE =62:00:00:01:CB:25:CA:28 1 ROM CODE =B6:00:00:01:CB:1B:9E:28 2 ROM CODE =66:00:00:01:CB:28:59:28 3 3 devices found. Scanning completed. Temp: 022.6875 Device: 000001CB25CA 001 Temp: 022.6875 Device: 000001CB1B9E 002 Temp: 027.6250 Device: 000001CB2859 003 Temp: 022.6250 Device: 000001CB25CA 001 Temp: 022.6875 Device: 000001CB1B9E 002 Temp: 025.3125 Device: 000001CB2859 003 Temp: 022.8125 Device: 000001CB25CA 001 Temp: 024.1875 Device: 000001CB1B9E 002 Temp: 023.7500 Device: 000001CB2859 003

Dependencies:   mbed

Committer:
RRacer
Date:
Tue Jan 10 12:32:05 2012 +0000
Revision:
2:7ab1bf8540a3
Child:
1:0777f93ef466
Example: using multiple DS18B20

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RRacer 2:7ab1bf8540a3 1 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 2 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 3 // Lots_of_DS18B20
RRacer 2:7ab1bf8540a3 4 // Demo on how to identify and read multiple DS18B20 connected to the same bus.
RRacer 2:7ab1bf8540a3 5 // Parasitic power is not used in this example.
RRacer 2:7ab1bf8540a3 6 // This program is based on the sample code from Maxim/Dallas application
RRacer 2:7ab1bf8540a3 7 // note 162 (http://www.maxim-ic.com/app-notes/index.mvp/id/162).
RRacer 2:7ab1bf8540a3 8 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 9 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 10
RRacer 2:7ab1bf8540a3 11 #include <mbed.h>
RRacer 2:7ab1bf8540a3 12 Serial pc(USBTX, USBRX);
RRacer 2:7ab1bf8540a3 13
RRacer 2:7ab1bf8540a3 14 #define FALSE 0
RRacer 2:7ab1bf8540a3 15 #define TRUE 1
RRacer 2:7ab1bf8540a3 16 #define MaxROMs 20 // Defines how many devices space is allocated for.
RRacer 2:7ab1bf8540a3 17
RRacer 2:7ab1bf8540a3 18 DigitalInOut DQ(p30);
RRacer 2:7ab1bf8540a3 19
RRacer 2:7ab1bf8540a3 20 unsigned char SPad[9]; // Scratchpad storage
RRacer 2:7ab1bf8540a3 21 unsigned char ROM[8];
RRacer 2:7ab1bf8540a3 22 unsigned char lastDiscrep = 0; // last discrepancy
RRacer 2:7ab1bf8540a3 23 unsigned char doneFlag = 0; // Done flag
RRacer 2:7ab1bf8540a3 24 unsigned char FoundROM[MaxROMs][8]; // table of found ROM codes
RRacer 2:7ab1bf8540a3 25 unsigned char numROMs; // Number of found devices.
RRacer 2:7ab1bf8540a3 26 unsigned char dowcrc;
RRacer 2:7ab1bf8540a3 27 unsigned char dscrc_table[] = {
RRacer 2:7ab1bf8540a3 28 0, 94,188,226, 97, 63,221,131,194,156,126, 32,163,253, 31, 65,
RRacer 2:7ab1bf8540a3 29 157,195, 33,127,252,162, 64, 30, 95, 1,227,189, 62, 96,130,220,
RRacer 2:7ab1bf8540a3 30 35,125,159,193, 66, 28,254,160,225,191, 93, 3,128,222, 60, 98,
RRacer 2:7ab1bf8540a3 31 190,224, 2, 92,223,129, 99, 61,124, 34,192,158, 29, 67,161,255,
RRacer 2:7ab1bf8540a3 32 70, 24,250,164, 39,121,155,197,132,218, 56,102,229,187, 89, 7,
RRacer 2:7ab1bf8540a3 33 219,133,103, 57,186,228, 6, 88, 25, 71,165,251,120, 38,196,154,
RRacer 2:7ab1bf8540a3 34 101, 59,217,135, 4, 90,184,230,167,249, 27, 69,198,152,122, 36,
RRacer 2:7ab1bf8540a3 35 248,166, 68, 26,153,199, 37,123, 58,100,134,216, 91, 5,231,185,
RRacer 2:7ab1bf8540a3 36 140,210, 48,110,237,179, 81, 15, 78, 16,242,172, 47,113,147,205,
RRacer 2:7ab1bf8540a3 37 17, 79,173,243,112, 46,204,146,211,141,111, 49,178,236, 14, 80,
RRacer 2:7ab1bf8540a3 38 175,241, 19, 77,206,144,114, 44,109, 51,209,143, 12, 82,176,238,
RRacer 2:7ab1bf8540a3 39 50,108,142,208, 83, 13,239,177,240,174, 76, 18,145,207, 45,115,
RRacer 2:7ab1bf8540a3 40 202,148,118, 40,171,245, 23, 73, 8, 86,180,234,105, 55,213,139,
RRacer 2:7ab1bf8540a3 41 87, 9,235,181, 54,104,138,212,149,203, 41,119,244,170, 72, 22,
RRacer 2:7ab1bf8540a3 42 233,183, 85, 11,136,214, 52,106, 43,117,151,201, 74, 20,246,168,
RRacer 2:7ab1bf8540a3 43 116, 42,200,150, 21, 75,169,247,182,232, 10, 84,215,137,107, 53};
RRacer 2:7ab1bf8540a3 44
RRacer 2:7ab1bf8540a3 45 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 46 // OW_RESET - performs a reset on the 1-wire bus and returns the presence detect.
RRacer 2:7ab1bf8540a3 47 unsigned char ow_reset(void) {
RRacer 2:7ab1bf8540a3 48 unsigned char presence;
RRacer 2:7ab1bf8540a3 49 DQ.output();
RRacer 2:7ab1bf8540a3 50 DQ = 0; //pull DQ line low
RRacer 2:7ab1bf8540a3 51 wait_us(480); // leave it low for 480us
RRacer 2:7ab1bf8540a3 52 DQ.input(); // allow line to return high
RRacer 2:7ab1bf8540a3 53 wait_us(70); // wait for presence
RRacer 2:7ab1bf8540a3 54 presence = DQ; // get presence signal
RRacer 2:7ab1bf8540a3 55 wait_us(410); // wait for end of timeslot
RRacer 2:7ab1bf8540a3 56 return(presence); // presence signal returned, 0=presence, 1 = no part
RRacer 2:7ab1bf8540a3 57 }
RRacer 2:7ab1bf8540a3 58
RRacer 2:7ab1bf8540a3 59 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 60 // READ_BIT - reads a bit from the one-wire bus.
RRacer 2:7ab1bf8540a3 61 unsigned char read_bit(void) {
RRacer 2:7ab1bf8540a3 62 unsigned char retval;
RRacer 2:7ab1bf8540a3 63 wait_us(1); // Recovery time
RRacer 2:7ab1bf8540a3 64 DQ.output();
RRacer 2:7ab1bf8540a3 65 DQ = 0; // pull DQ low to start timeslot
RRacer 2:7ab1bf8540a3 66 wait_us(2);
RRacer 2:7ab1bf8540a3 67 DQ.input(); // Tristate line
RRacer 2:7ab1bf8540a3 68 wait_us(10); // delay 10 us from start of timeslot
RRacer 2:7ab1bf8540a3 69 retval=DQ;
RRacer 2:7ab1bf8540a3 70 wait_us(48); // minimum Read time slot: 60 us.
RRacer 2:7ab1bf8540a3 71 return(retval); // return value of DQ line
RRacer 2:7ab1bf8540a3 72 }
RRacer 2:7ab1bf8540a3 73
RRacer 2:7ab1bf8540a3 74 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 75 // WRITE_BIT - writes a bit to the one-wire bus, passed in bitval.
RRacer 2:7ab1bf8540a3 76 void write_bit(unsigned char bitval) {
RRacer 2:7ab1bf8540a3 77 wait_us(1); // Recovery time
RRacer 2:7ab1bf8540a3 78 DQ.output();
RRacer 2:7ab1bf8540a3 79 DQ = 0; // pull DQ low to start timeslot
RRacer 2:7ab1bf8540a3 80 wait_us(10);
RRacer 2:7ab1bf8540a3 81 if(bitval==1) DQ =1; // return DQ high if write 1
RRacer 2:7ab1bf8540a3 82 wait_us(50); // hold value for remainder of timeslot
RRacer 2:7ab1bf8540a3 83 DQ.input(); // Release line
RRacer 2:7ab1bf8540a3 84 }
RRacer 2:7ab1bf8540a3 85
RRacer 2:7ab1bf8540a3 86 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 87 // READ_BYTE - reads a byte from the one-wire bus.
RRacer 2:7ab1bf8540a3 88 unsigned char read_byte(void) {
RRacer 2:7ab1bf8540a3 89 unsigned char i, value=0;
RRacer 2:7ab1bf8540a3 90 for (i=0;i<8;i++) {
RRacer 2:7ab1bf8540a3 91 if(read_bit()) value|=0x01<<i; // reads byte in, one byte at a time and then shifts it left
RRacer 2:7ab1bf8540a3 92 }
RRacer 2:7ab1bf8540a3 93 return(value);
RRacer 2:7ab1bf8540a3 94 }
RRacer 2:7ab1bf8540a3 95
RRacer 2:7ab1bf8540a3 96 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 97 // WRITE_BYTE - writes a byte to the one-wire bus.
RRacer 2:7ab1bf8540a3 98 void write_byte(char val) {
RRacer 2:7ab1bf8540a3 99 unsigned char i;
RRacer 2:7ab1bf8540a3 100 unsigned char temp;
RRacer 2:7ab1bf8540a3 101 for (i=0; i<8; i++) {// writes byte, one bit at a time
RRacer 2:7ab1bf8540a3 102 temp = val>>i; // shifts val right 'i' spaces
RRacer 2:7ab1bf8540a3 103 temp &= 0x01; // copy that bit to temp
RRacer 2:7ab1bf8540a3 104 write_bit(temp); // write bit in temp into
RRacer 2:7ab1bf8540a3 105 }
RRacer 2:7ab1bf8540a3 106 }
RRacer 2:7ab1bf8540a3 107
RRacer 2:7ab1bf8540a3 108 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 109 // ONE WIRE CRC
RRacer 2:7ab1bf8540a3 110 unsigned char ow_crc( unsigned char x) {
RRacer 2:7ab1bf8540a3 111 dowcrc = dscrc_table[dowcrc^x];
RRacer 2:7ab1bf8540a3 112 return dowcrc;
RRacer 2:7ab1bf8540a3 113 }
RRacer 2:7ab1bf8540a3 114
RRacer 2:7ab1bf8540a3 115 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 116 // NEXT
RRacer 2:7ab1bf8540a3 117 // The Next function searches for the next device on the 1-Wire bus. If
RRacer 2:7ab1bf8540a3 118 // there are no more devices on the 1-Wire then false is returned.
RRacer 2:7ab1bf8540a3 119 unsigned char Next(void) {
RRacer 2:7ab1bf8540a3 120 unsigned char m = 1; // ROM Bit index
RRacer 2:7ab1bf8540a3 121 unsigned char n = 0; // ROM Byte index
RRacer 2:7ab1bf8540a3 122 unsigned char k = 1; // bit mask
RRacer 2:7ab1bf8540a3 123 unsigned char x = 0;
RRacer 2:7ab1bf8540a3 124 unsigned char discrepMarker = 0; // discrepancy marker
RRacer 2:7ab1bf8540a3 125 unsigned char g; // Output bit
RRacer 2:7ab1bf8540a3 126 unsigned char nxt; // return value
RRacer 2:7ab1bf8540a3 127 int flag;
RRacer 2:7ab1bf8540a3 128 nxt = FALSE; // set the next flag to false
RRacer 2:7ab1bf8540a3 129 dowcrc = 0; // reset the dowcrc
RRacer 2:7ab1bf8540a3 130 flag = ow_reset(); // reset the 1-Wire
RRacer 2:7ab1bf8540a3 131 if(flag||doneFlag) { // no parts -> return false
RRacer 2:7ab1bf8540a3 132 lastDiscrep = 0; // reset the search
RRacer 2:7ab1bf8540a3 133 return FALSE;
RRacer 2:7ab1bf8540a3 134 }
RRacer 2:7ab1bf8540a3 135 write_byte(0xF0); // send SearchROM command
RRacer 2:7ab1bf8540a3 136 do { // for all eight bytes
RRacer 2:7ab1bf8540a3 137 x = 0;
RRacer 2:7ab1bf8540a3 138 if(read_bit()==1) x = 2;
RRacer 2:7ab1bf8540a3 139 wait_us(120);
RRacer 2:7ab1bf8540a3 140 if(read_bit()==1) x |= 1; // and its complement
RRacer 2:7ab1bf8540a3 141 if(x ==3) // there are no devices on the 1-Wire
RRacer 2:7ab1bf8540a3 142 break;
RRacer 2:7ab1bf8540a3 143 else {
RRacer 2:7ab1bf8540a3 144 if(x>0) // all devices coupled have 0 or 1
RRacer 2:7ab1bf8540a3 145 g = x>>1; // bit write value for search
RRacer 2:7ab1bf8540a3 146 else {
RRacer 2:7ab1bf8540a3 147 // if this discrepancy is before the last discrepancy on a previous Next then pick the same as last time
RRacer 2:7ab1bf8540a3 148 if(m<lastDiscrep)
RRacer 2:7ab1bf8540a3 149 g = ((ROM[n]&k)>0);
RRacer 2:7ab1bf8540a3 150 else // if equal to last pick 1
RRacer 2:7ab1bf8540a3 151 g = (m==lastDiscrep); // if not then pick 0
RRacer 2:7ab1bf8540a3 152 // if 0 was picked then record position with mask k
RRacer 2:7ab1bf8540a3 153 if (g==0) discrepMarker = m;
RRacer 2:7ab1bf8540a3 154 }
RRacer 2:7ab1bf8540a3 155 if(g==1) // isolate bit in ROM[n] with mask k
RRacer 2:7ab1bf8540a3 156 ROM[n] |= k;
RRacer 2:7ab1bf8540a3 157 else
RRacer 2:7ab1bf8540a3 158 ROM[n] &= ~k;
RRacer 2:7ab1bf8540a3 159 write_bit(g); // ROM search write
RRacer 2:7ab1bf8540a3 160 m++; // increment bit counter m
RRacer 2:7ab1bf8540a3 161 k = k<<1; // and shift the bit mask k
RRacer 2:7ab1bf8540a3 162 if(k==0) { // if the mask is 0 then go to new ROM // byte n and reset mask
RRacer 2:7ab1bf8540a3 163 ow_crc(ROM[n]); // accumulate the CRC
RRacer 2:7ab1bf8540a3 164 n++; k++;
RRacer 2:7ab1bf8540a3 165 }
RRacer 2:7ab1bf8540a3 166 }
RRacer 2:7ab1bf8540a3 167 }
RRacer 2:7ab1bf8540a3 168 while(n<8); //loop until through all ROM bytes 0-7
RRacer 2:7ab1bf8540a3 169 if(m<65||dowcrc) // if search was unsuccessful then
RRacer 2:7ab1bf8540a3 170 lastDiscrep=0; // reset the last discrepancy to 0
RRacer 2:7ab1bf8540a3 171 else { // search was successful, so set lastDiscrep, lastOne, nxt
RRacer 2:7ab1bf8540a3 172 lastDiscrep = discrepMarker;
RRacer 2:7ab1bf8540a3 173 doneFlag = (lastDiscrep==0);
RRacer 2:7ab1bf8540a3 174 nxt = TRUE; // indicates search is not complete yet, more parts remain
RRacer 2:7ab1bf8540a3 175 }
RRacer 2:7ab1bf8540a3 176 return nxt;
RRacer 2:7ab1bf8540a3 177 }
RRacer 2:7ab1bf8540a3 178
RRacer 2:7ab1bf8540a3 179 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 180 // FIRST
RRacer 2:7ab1bf8540a3 181 // The First function resets the current state of a ROM search and calls
RRacer 2:7ab1bf8540a3 182 // Next to find the first device on the 1-Wire bus.
RRacer 2:7ab1bf8540a3 183 unsigned char First(void) {
RRacer 2:7ab1bf8540a3 184 lastDiscrep = 0; // reset the rom search last discrepancy global
RRacer 2:7ab1bf8540a3 185 doneFlag = FALSE;
RRacer 2:7ab1bf8540a3 186 return Next(); // call Next and return its return value
RRacer 2:7ab1bf8540a3 187 }
RRacer 2:7ab1bf8540a3 188
RRacer 2:7ab1bf8540a3 189 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 190 // FIND DEVICES
RRacer 2:7ab1bf8540a3 191 void FindDevices(void) {
RRacer 2:7ab1bf8540a3 192 unsigned char m;
RRacer 2:7ab1bf8540a3 193 if(!ow_reset()) { //Begins when a presence is detected
RRacer 2:7ab1bf8540a3 194 if(First()) { //Begins when at least one part is found
RRacer 2:7ab1bf8540a3 195 numROMs=0;
RRacer 2:7ab1bf8540a3 196 do {
RRacer 2:7ab1bf8540a3 197 numROMs++;
RRacer 2:7ab1bf8540a3 198 for(m=0;m<8;m++) {
RRacer 2:7ab1bf8540a3 199 FoundROM[numROMs][m]=ROM[m]; //Identifies ROM
RRacer 2:7ab1bf8540a3 200 }
RRacer 2:7ab1bf8540a3 201 pc.printf("ROM CODE =%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X %d\r\n",
RRacer 2:7ab1bf8540a3 202 FoundROM[numROMs][7],FoundROM[numROMs][6],FoundROM[numROMs][5],FoundROM[numROMs][4],
RRacer 2:7ab1bf8540a3 203 FoundROM[numROMs][3],FoundROM[numROMs][2],FoundROM[numROMs][1],FoundROM[numROMs][0],numROMs);
RRacer 2:7ab1bf8540a3 204 }
RRacer 2:7ab1bf8540a3 205 while (Next()&&(numROMs<MaxROMs)); //Continues until no additional devices are found
RRacer 2:7ab1bf8540a3 206 }
RRacer 2:7ab1bf8540a3 207 }
RRacer 2:7ab1bf8540a3 208 pc.printf("\n%d devices found.\r\n\n",numROMs);
RRacer 2:7ab1bf8540a3 209 }
RRacer 2:7ab1bf8540a3 210 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 211 void Read_ScratchPad(unsigned char n) { // Read the n first scratchpad bytes. Old data not wiped.
RRacer 2:7ab1bf8540a3 212 n=n % 10;
RRacer 2:7ab1bf8540a3 213 write_byte(0xBE);
RRacer 2:7ab1bf8540a3 214 for (int j=1;j<=n;j++){SPad[j-1]=read_byte();}
RRacer 2:7ab1bf8540a3 215 // CRC ********reserved******* Config Tl Th T MSB T LSB
RRacer 2:7ab1bf8540a3 216 pc.printf("\n ScratchPAD: %X%X%X%X%X%X%X%X%X\n",SPad[8],SPad[7],SPad[6],SPad[5],SPad[4],SPad[3],SPad[2],SPad[1],SPad[0]);
RRacer 2:7ab1bf8540a3 217 }
RRacer 2:7ab1bf8540a3 218
RRacer 2:7ab1bf8540a3 219 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 220 // Perform Match ROM
RRacer 2:7ab1bf8540a3 221 unsigned char Send_MatchRom(unsigned char DeviceNo) {
RRacer 2:7ab1bf8540a3 222 unsigned char i;
RRacer 2:7ab1bf8540a3 223 if(ow_reset()) return false;
RRacer 2:7ab1bf8540a3 224 write_byte(0x55); // match ROM
RRacer 2:7ab1bf8540a3 225 for(i=0;i<8;i++) {
RRacer 2:7ab1bf8540a3 226 write_byte(FoundROM[DeviceNo][i]); //send ROM code
RRacer 2:7ab1bf8540a3 227 }
RRacer 2:7ab1bf8540a3 228 return true;
RRacer 2:7ab1bf8540a3 229 }
RRacer 2:7ab1bf8540a3 230
RRacer 2:7ab1bf8540a3 231 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 232 void ConvT() { // Make all devices on the bus start a temperature conversion.
RRacer 2:7ab1bf8540a3 233 ow_reset();
RRacer 2:7ab1bf8540a3 234 write_byte( 0xcc); // Skip ROM command.
RRacer 2:7ab1bf8540a3 235 write_byte( 0x44); // Convert T command.
RRacer 2:7ab1bf8540a3 236 }
RRacer 2:7ab1bf8540a3 237
RRacer 2:7ab1bf8540a3 238 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 239 unsigned int ReadRawTemp(unsigned char device) {
RRacer 2:7ab1bf8540a3 240 int HighByte, LowByte;
RRacer 2:7ab1bf8540a3 241 Send_MatchRom(device); // Select device.
RRacer 2:7ab1bf8540a3 242 write_byte( 0xbe); // Read Scratchpad command.
RRacer 2:7ab1bf8540a3 243 LowByte=read_byte();
RRacer 2:7ab1bf8540a3 244 HighByte=read_byte();
RRacer 2:7ab1bf8540a3 245 return (HighByte << 8) + LowByte;
RRacer 2:7ab1bf8540a3 246 }
RRacer 2:7ab1bf8540a3 247
RRacer 2:7ab1bf8540a3 248 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 249 float Get_Temp(unsigned char device) {
RRacer 2:7ab1bf8540a3 250 float temperature = (float)ReadRawTemp(device) / 16.0;
RRacer 2:7ab1bf8540a3 251 return temperature;
RRacer 2:7ab1bf8540a3 252 }
RRacer 2:7ab1bf8540a3 253
RRacer 2:7ab1bf8540a3 254 //////////////////////////////////////////////////////////////////////////////
RRacer 2:7ab1bf8540a3 255 int main() {
RRacer 2:7ab1bf8540a3 256 float temperature;
RRacer 2:7ab1bf8540a3 257 DQ.output();
RRacer 2:7ab1bf8540a3 258 DQ = 0;
RRacer 2:7ab1bf8540a3 259 DQ.input();
RRacer 2:7ab1bf8540a3 260 pc.baud(9600);
RRacer 2:7ab1bf8540a3 261 pc.printf("\n\n*** Test with multiple DS18B20 ***\r\n\n");
RRacer 2:7ab1bf8540a3 262 pc.printf("Memory allocated for %d devices.\r\n",MaxROMs);
RRacer 2:7ab1bf8540a3 263 pc.printf("Scanning for devices...\r\n");
RRacer 2:7ab1bf8540a3 264 ow_reset();
RRacer 2:7ab1bf8540a3 265 FindDevices();
RRacer 2:7ab1bf8540a3 266 pc.printf("Scanning completed.\r\n");
RRacer 2:7ab1bf8540a3 267
RRacer 2:7ab1bf8540a3 268 while (1) {
RRacer 2:7ab1bf8540a3 269 ConvT(); // Issue Convert T command.
RRacer 2:7ab1bf8540a3 270 wait_ms(750); // Minimum 12-bit conversion time.
RRacer 2:7ab1bf8540a3 271 for(int i=1;i<=numROMs;i++) { // Cycle through found devices.
RRacer 2:7ab1bf8540a3 272 temperature = Get_Temp(i);
RRacer 2:7ab1bf8540a3 273 pc.printf("Temp: %08.4f Device: %02X%02X%02X%02X%02X%02X %03d\r\n",temperature,FoundROM[i][6],FoundROM[i][5],FoundROM[i][4],FoundROM[i][3],FoundROM[i][2],FoundROM[i][1],i);
RRacer 2:7ab1bf8540a3 274 }
RRacer 2:7ab1bf8540a3 275 pc.printf("\r\n");
RRacer 2:7ab1bf8540a3 276 wait(5); // Doing conversions more often will make devices self heat and produce a higher temperature reading.
RRacer 2:7ab1bf8540a3 277 }
RRacer 2:7ab1bf8540a3 278 }