Skip to content

Commit

Permalink
Fixed negative temperature bug
Browse files Browse the repository at this point in the history
In read_temp() the temperature was not converted according to
DS1620 specification.
  • Loading branch information
Paul Ring committed Dec 18, 2010
1 parent 625f8b5 commit 22c9803
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
30 changes: 15 additions & 15 deletions README
@@ -1,15 +1,15 @@
Arduino DS1620 Library 0.1
Copyright (C) 2010 John P. Mulligan. All rights reserved.
This is an Arduino library for use with the Dallas Semiconductor DS1620 Digital
Thermometer and Thermostat. Uses 3-wire serial communication.
Latest version of library:
http://github.com/thinkhole/Arduino-DS1620
Project wiki:
http://wiki.thinkhole.org/ds1620
See INSTALL file for installation instructions.
Arduino DS1620 Library 0.2
Copyright (C) 2010 John P. Mulligan. All rights reserved.

This is an Arduino library for use with the Dallas Semiconductor DS1620 Digital
Thermometer and Thermostat. Uses 3-wire serial communication.

Latest version of library:

http://github.com/thinkhole/Arduino-DS1620

Project wiki:

http://wiki.thinkhole.org/ds1620

See INSTALL file for installation instructions.
21 changes: 17 additions & 4 deletions ds1620.cpp
Expand Up @@ -66,14 +66,27 @@ DS1620::DS1620(int DQ, int CLK, int RST)

int DS1620::read_temp()
{
int t;
short t;

rst_start();
send_command(READ_TEMP); // Next 9 clock cycles, last temp conv result
t = receive_data()/2;
t = (short)receive_data();
rst_stop();

// Check sign bit from Temp
if (t & 0x0100)
{
// Temperature is negative
// According to specification: [256 (0x0100) - Temp]
t &= 0x00FF; // Remove the sign bit
t = 0x0100 - t;
t *= (short)-1;
}

t /= 2;

return(t);
}
}

void DS1620::write_th(int high_temp)
{
Expand Down

0 comments on commit 22c9803

Please sign in to comment.