Question on MAX31855 code
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Question on MAX31855 code

by fwfreak on Tue Jan 01, 2013 3:19 pm

I am using one of the MAX31855 breakout boards on a oven controller I'm building and went to the github site for the Adafruit code. I found a number of issues with the existing code, to the point that I rewrote it and posted the revised code on my website: http://www.seanet.com/~karllunt/max31855.html

Note that my code is C, not C++. If you are heavily into Arduino, this is going to look very different from the sketches you're used to.

One question I had with the code is it doesn't appear to handle negative thermocouple values correctly in gcc-avr. It does seem to handle negative reference values properly, but that doesn't help you with the thermocouple.

Specifically, this code in Adafruit_MAX31855::readCelsius(void) seems wrong:
// get rid of internal temp data, and any fault bits
v >>= 18; <-- this does not sign-extend in the gcc-avr compiler
//Serial.println(v, HEX);

// pull the bottom 13 bits off <-- actually, the bottom 13 bits plus 1 sign bit
int16_t temp = v & 0x3FFF;

// check sign bit
if (v & 0x2000)
temp |= 0xC000;

double centigrade = v; <-- again, sign is not extended (in gcc-avr) so centigrade is always positive

// LSB = 0.25 degrees C
centigrade *= 0.25;
return centigrade;

Notice that the true sign bit of the data value is tested and recorded in temp but is never subsequently used.

There is a println() immediately after the right-shift of v, so this code was tested under at least some conditions; was it tested with negative temperature values generated by the device? Does the Arduino compiler do sign-extension on right-shift? (I don't use that toolset so can't test.)

Posts: 1
Joined: Tue Jan 01, 2013 2:32 pm

Re: Question on MAX31855 code

by adafruit_support_bill on Wed Jan 02, 2013 7:51 am

Thanks for the analysis. Can you post this as an issue to Github? That will make sure it gets on our schedule of fixes.

Posts: 70470
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.