Join GitHub today
Library code appears to process negative thermocouple values incorrectly #3
I posted a comment in the Adafruit forum on sensors regarding issues with the MAX31855 library code. The routine that reads the thermocouple value (not the internal value) does not properly convert negative values. The issue lies with the use of >> for negative numbers. Sign-extension by >> is compiler specific. The gcc-avr compiler, which I use, does NOT sign extend. I don't know if the Arduino compiler does.
Regardless, the sign bit is tested and only recorded in the variable temp, which is then not used again. The conversion of v (int) to centigrade (double) does not include sign info if >> does not sign-extend.
I have written my own version of these routines in ANSI C for use with the gcc-avr compiler. You can find them at: www.seanet.com/~karllunt. Please feel free to add them to github if you think that is appropriate.