Skip to content

Commit 5be8503

Browse files
committed
+ fixed negative temperatures (internal too)
1 parent 9b2fe13 commit 5be8503

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

libraries/MAX31855/MAX31855.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//
22
// FILE: MAX31855.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.02
4+
// VERSION: 0.1.03
55
// PURPOSE: MAX31855 - Thermocouple
66
// DATE: 2014-01-01
77
// URL:
88
//
9-
// HISTORY:
9+
// HISTORY:
10+
// 0.1.03 fixed negative temperature
1011
// 0.1.02 added offset
1112
// 0.1.01 refactored speed/performance
1213
// 0.1.00 initial version.
@@ -46,7 +47,10 @@ uint8_t MAX31855::read()
4647

4748
// process internal bit 4-15
4849
_internal = (value & 0x07FF) * 0.0625;
49-
if (value & 0x0800) _internal *= -1;
50+
if (value & 0x0800)
51+
{
52+
_internal = -128 + _internal; // fix neg temp
53+
}
5054
value >>= 12;
5155

5256
// Fault bit ignored as we have the 3 status bits
@@ -58,7 +62,10 @@ uint8_t MAX31855::read()
5862

5963
// process temperature bit 18-31
6064
_temperature = (value & 0x1FFF) * 0.25;
61-
if (value & 0x2000) _temperature *= -1;
65+
if (value & 0x2000) // negative flag
66+
{
67+
_temperature = -2048 + _temperature; // fix neg temp
68+
}
6269
if (_offset != 0) _temperature += _offset;
6370

6471
return _status;

libraries/MAX31855/MAX31855.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// FILE: MAX31855.h
55
// AUTHOR: Rob Tillaart
6-
// VERSION: 0.1.02
6+
// VERSION: 0.1.03
77
// PURPOSE: MAX31855 - Thermocouple
88
// DATE: 2014-01-01
99
// URL:
@@ -17,7 +17,7 @@
1717
#include "Arduino.h"
1818
#endif
1919

20-
#define MAX31855_VERSION "0.1.02"
20+
#define MAX31855_VERSION "0.1.03"
2121

2222
#define STATUS_OK 0x00
2323
#define STATUS_OPEN_CIRCUIT 0x01
@@ -34,10 +34,10 @@ class MAX31855
3434
// Celsius
3535
float getTemperature(void) { return _temperature; };
3636
uint8_t getStatus(void) {return _status; };
37-
37+
3838
void setOffset(float t) { _offset = t; };
3939
float getOffset(float t) { return _offset; };
40-
40+
4141

4242
private:
4343
uint32_t _read();

0 commit comments

Comments
 (0)