I have a circuit which used a MAX31855KASA+ thermocouple IC.
The circuit as a whole works fine, and does everything as I expect it to except the MAX31855 its self. I have tried 3 different thermocouples and 2 other thermocouple meters, every time my circuit gives me a reading which at 19C (real temperature) is reading 9C from the IC, and 36C real temperature is reading 26C from the IC.
I have also found that I have 1 more bit than I should have.
If I read the IC I get the following output (read 40-bits):
0000000001001010000010101011100000000000
According to this, the temperature is "1001" (as can be seen as you go left to right) giving me 9C. Then the "01" means 9.25C. This is where the other 2 meters are telling me 19C.
Should I disconnect the probe I get:
0011111111111110100010101011100010000000
Telling me there is an error, and according to the datasheet this is Bit 16 (counting back from bit-31 left-most) but it counts as bit 15. Maybe this is an error in my code?
The main point is my temperature is always out and I have no idea why.
void tempMeasure1()
{
temp1 = 0; // Clears temp1digitalWrite(sck, HIGH); // Ensures the Serial Clock is High
digitalWrite(cs1, LOW); // Selects Temp Chip 1
byte i = 32; // i = 31 for 31 bits sent from the Temperature Chip
byte two = 31; // For use with 2's Compliment Calculations
if (digitalRead(so) == 1) // Reads if 2's compliment is active. If Serial Out = 1 (negative), sets temp1 negative.
{
for (two = 31; two > 10; two--) // Counts from Bit 31 to Bit 11 to set "1" for 2's compliment to fill in blanks.
{
bitSet(temp1, two); // Writes bit 31 (2's compliment) (temp1 being a 32-bit int on the SMD version)
}
}i = i--; // Sets i to 30 for the next function
digitalWrite(sck, LOW); // Pulses the Serial clock Low and High again
delayMicroseconds(2);
digitalWrite(sck, HIGH);
delayMicroseconds(2);for (i = 31; i > 19; i--)
{
if (digitalRead(so) == 0) // Reads SO. Sets temp1 Bits 10 to 0 the same as Bits 30 to 20 of SO.
{
bitClear(temp1, (i - 20));
}
else
{
bitSet(temp1, (i - 20)); // Else if Serial Out = 1, set Bit (i - 19) of temp1 to 1.
}digitalWrite(sck, LOW); // Pulses the Serial clock Low and High again
delayMicroseconds(2);
digitalWrite(sck, HIGH);
delayMicroseconds(2);
}for (i = 19; i > 17; i--)
{
if (digitalRead(so) == 0) // if Serial Out = 0, set Bit (i - 17) of temp1dec to 0.
{
bitClear(temp1dec, (i - 18));
}
else
{
bitSet(temp1dec, (i - 18)); // Else if Serial Out = 1, set Bit (i - 17) of temp1dec to 1.
}digitalWrite(sck, LOW); // Pulses the Serial clock Low and High again
delayMicroseconds(2);
digitalWrite(sck, HIGH);
delayMicroseconds(2);
}for (i = 17; i > 2; i--) // This simply clock through bits 16 to 3, they are not required.
{if (i == 16)
{
probe1Error = digitalRead(so);
}digitalWrite(sck, LOW); // Pulses the Serial clock Low and High again
delayMicroseconds(2);
digitalWrite(sck, HIGH);
delayMicroseconds(2);
}for (i = 2; i > 0; i--) // Reads Error Bits 2, 1 and 0.
{
if (digitalRead(so) == 0) // if Serial Out = 0, set Bit i of temp1Stat to 0.
{
bitClear(temp1Stat, (i));
}
else
{
bitSet(temp1Stat, (i)); // Else if Serial Out = 1, set Bit i of temp1Stat to 1.
}digitalWrite(sck, LOW); // Pulses the Serial clock Low and High again
delayMicroseconds(2);
digitalWrite(sck, HIGH);
delayMicroseconds(2);
}// Runs this because i can't be -1 to exit the loop above
if (digitalRead(so) == 0) // if Serial Out = 0, set Bit i of temp1Stat to 0.
{
bitClear(temp1Stat, (i));
}
else
{
bitSet(temp1Stat, (i)); // Else if Serial Out = 1, set Bit i of temp1Stat to 1.
}digitalWrite(cs1, HIGH); // Deselects Temp Chip 1
digitalWrite(sck, HIGH); // Ensures the Serial Clock is High
if (temp1 > -21 && temp1 < 41 && probe1Error == 0) // Checks there are no errors and within range
{
if (bitRead(tempError, 1) == 1)
{
string = " "; // Clears the LCD before writing stringlcd(0, 1, 16); // Displays the Temperature on the LCD Char Data lcd(Col, Line, Length)
bitClear(tempError, 1); // Clears the Error Bit 1
digitalWrite(led, LOW);if (probe == 1) // Checks the selected Probe
{
string = " "; // This sets a * on Temp 2 and Blank on Temp 1.
lcd(0, 1, 1); // Sends LCD Char Data lcd(Col, Line, Length)
string = "";
lcd(0, 2, 1); // Sends LCD Char Data lcd(Col, Line, Length)
}
else
{
string = ""; // This sets a * on Temp 2 and Blank on Temp 1.
lcd(0, 1, 1); // Sends LCD Char Data lcd(Col, Line, Length)
string = " ";
lcd(0, 2, 1); // Sends LCD Char Data lcd(Col, Line, Length)
}
}string = String(temp1, DEC) + "UC"; // Sets the string to the temperature, Degrees = ASCII 223
lcd(1, 1, 5); // Displays the Temperature on the LCD Char Data lcd(Col, Line, Length)
if (probe == 0) // if Probe is set to 0, use Temperature 1 for the volume calculation
{
petrolCalc(temp1); // Runs the Petrol Calibration function using the current temperaturedieselCalc(temp1); // Runs the Petrol Calibration function using the current temperature
}
}if (temp1 < -20) // If Temperature is under 21C
{
string = "Too Cold!"; // Sets the string to the temperature, Degrees = ASCII 223bitSet(tempError, 1); // Sets Temp Error Bit 1 to 1 so the LCD can be cleared when the error is cleared.
lcd(1, 1, 15); // Sends LCD Char Data lcd(Col, Line, Length)
}if (temp1 > 40) // If Temperature is under 21C
{
string = "Too Hot!"; // Sets the string to the temperature, Degrees = ASCII 223bitSet(tempError, 1); // Sets Temp Error Bit 1 to 1 so the LCD can be cleared when the error is cleared.
lcd(1, 1, 15); // Sends LCD Char Data lcd(Col, Line, Length)
}if (bitRead(temp1Stat, 0) == 1) // Detects if the Probe is Open Circuit
{
string = "ProbeFault: Open";digitalWrite(led, HIGH);
bitSet(tempError, 1); // Sets Temp Error Bit 1 to 1 so the LCD can be cleared when the error is cleared.
lcd (0, 1, 16); // Sends LCD Char Data lcd(Col, Line, Length)
}if (bitRead(temp1Stat, 1) == 1) // Detects if the Probe is shorted to Ground
{
string = "Probe Gnd Short ";digitalWrite(led, HIGH);
bitSet(tempError, 1); // Sets Temp Error Bit 1 to 1 so the LCD can be cleared when the error is cleared.
lcd (0, 1, 16); // Sends LCD Char Data lcd(Col, Line, Length)
}if (bitRead(temp1Stat, 2) == 1) // Detects if the Probe is shorted to VCC
{
string = "Probe VCC Short ";digitalWrite(led, HIGH);
bitSet(tempError, 1); // Sets Temp Error Bit 1 to 1 so the LCD can be cleared when the error is cleared.
lcd (0, 1, 16); // Sends LCD Char Data lcd(Col, Line, Length)
}
}