Dallas / Maxim DS1820 1-Wire library. For communication with multiple DS1820 on a single 1-Wire bus. Also supports DS18S20 and DS18B20.
Diff: DS1820.cpp
- Revision:
- 5:31e245719610
- Parent:
- 4:c2b93dbd6a9e
diff -r c2b93dbd6a9e -r 31e245719610 DS1820.cpp --- a/DS1820.cpp Fri Sep 28 22:29:43 2018 +0000 +++ b/DS1820.cpp Sun Feb 17 22:21:24 2019 +0000 @@ -6,6 +6,7 @@ int DS1820_last_descrepancy; char DS1820_search_Rom[8]; +extern Serial pc; DS1820::DS1820 (PinName data_pin, PinName power_pin) : _datapin(data_pin), _parasitepin(power_pin) { int byte_counter; @@ -282,6 +283,10 @@ for(i=0;i<9;i++) { RAM[i] = onewire_byte_in(); } + +// for(i=0;i<9;i++) { +// pc.printf("RAM[%d] = %d\r\n",i,RAM[i]); +// } } bool DS1820::set_configuration_bits(unsigned int resolution) { @@ -361,16 +366,18 @@ if (reading & 0x8000) { // negative degrees C reading = 0-((reading ^ 0xffff) + 1); // 2's comp then convert to signed int } + answer = reading +0.0f; // convert to floating point if ( FAMILY_CODE == FAMILY_CODE_DS18B20 ) { answer = answer / 8.0f; - printf("FAMILY_CODE_DS18B20\r\n"); + //answer = (answer -256) / 10.0f; + //printf("FAMILY_CODE_DS18B20 -> %d Temp: %1.1f\r\n",FAMILY_CODE, answer); } else { remaining_count = RAM[2]; count_per_degree = RAM[3]; answer = answer - 0.25f + (count_per_degree - remaining_count) / count_per_degree; - printf("FAMILY_CODE_OTHER\r\n"); + //printf("FAMILY_CODE_OTHER - Code: %d\r\n"),FAMILY_CODE; } if (scale=='C' or scale=='c') answer = answer / 2.0f; @@ -378,7 +385,7 @@ // Convert to deg F answer = answer * 9.0f / 10.0f + 32.0f; //return answer; - return reading; + return answer; } bool DS1820::read_power_supply(devices device) {