ds18b20 work for ST Nucleo

Dependencies:   mbed

Committer:
TuanPM
Date:
Thu Mar 27 17:26:59 2014 +0000
Revision:
1:10bbb8a13329
Parent:
0:6cb99f312e0e
First release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TuanPM 0:6cb99f312e0e 1 #include "mbed.h"
TuanPM 0:6cb99f312e0e 2 #include "DS1820.h"
TuanPM 0:6cb99f312e0e 3
TuanPM 0:6cb99f312e0e 4 Serial pc(SERIAL_TX, SERIAL_RX);
TuanPM 0:6cb99f312e0e 5
TuanPM 0:6cb99f312e0e 6 const int MAX_PROBES = 3;
TuanPM 0:6cb99f312e0e 7 DS1820 probe[3] = {D2, D2, D2};
TuanPM 0:6cb99f312e0e 8
TuanPM 0:6cb99f312e0e 9
TuanPM 0:6cb99f312e0e 10 int main()
TuanPM 0:6cb99f312e0e 11 {
TuanPM 1:10bbb8a13329 12 int i;
TuanPM 0:6cb99f312e0e 13 int devices_found=0;
TuanPM 0:6cb99f312e0e 14
TuanPM 0:6cb99f312e0e 15 //pc.attach(&pcRx, pc.RxIrq);
TuanPM 0:6cb99f312e0e 16 pc.printf("Started\r\n");
TuanPM 0:6cb99f312e0e 17
TuanPM 0:6cb99f312e0e 18 pc.printf("search_ROM_setup\r\n");
TuanPM 0:6cb99f312e0e 19 probe[0].search_ROM_setup();
TuanPM 0:6cb99f312e0e 20 pc.printf("search_ROM\r\n");
TuanPM 0:6cb99f312e0e 21 while (probe[devices_found].search_ROM() and devices_found<MAX_PROBES-1)
TuanPM 0:6cb99f312e0e 22 devices_found++;
TuanPM 0:6cb99f312e0e 23
TuanPM 0:6cb99f312e0e 24 // If maximum number of probes are found,
TuanPM 0:6cb99f312e0e 25 // bump the counter to include the last array entry
TuanPM 0:6cb99f312e0e 26 if (probe[devices_found].ROM[0] != 0xFF)
TuanPM 0:6cb99f312e0e 27 devices_found++;
TuanPM 0:6cb99f312e0e 28 pc.printf("devices found:%d\r\n", devices_found);
TuanPM 0:6cb99f312e0e 29
TuanPM 0:6cb99f312e0e 30
TuanPM 0:6cb99f312e0e 31 while(1) {
TuanPM 0:6cb99f312e0e 32 probe[0].convert_temperature(DS1820::all_devices);
TuanPM 0:6cb99f312e0e 33 for (i=0; i<devices_found; i++) {
TuanPM 0:6cb99f312e0e 34 pc.printf("Device[%d]: %3.1f \r\n",i, probe[i].temperature('c'));
TuanPM 0:6cb99f312e0e 35 }
TuanPM 0:6cb99f312e0e 36 wait(1.0); // 1 sec
TuanPM 0:6cb99f312e0e 37 }
TuanPM 0:6cb99f312e0e 38 }