Library to interface with the MAX31855 Cold Junction Compensated Thermocouple-to-Digital Converter

Dependents:   max31855Sample Reflow_Oven_Controller test_draft Soldering_Tips_Thermometer

Interface library for the MAX31855 Cold Junction Compendated Thermocouple-to-Digital Converter. This part is the reaplacement for the now discontinued MAX6675. The library is based on the original MAX6675 library found on this site altered to fit the serial specification of the new chip as well as adding a few new features.

The main new feature of note is that the library itself deals with the 0.25 second delay required to complete a conversion. Polling the 'ready()' function will return a '1' when the chip is read to submit a new reading.

Sample Program

#include "mbed.h"
#include "max31855.h"

DigitalOut myled(LED1);

//----------------------------------------------------------
//SPI Interfaces
SPI testSPI(p11,p12,p13);
//----------------------------------------------------------

//----------------------------------------------------------
//Thermocouples
max31855 max1(testSPI,p21);
//----------------------------------------------------------

int main() {
    //Initialise chip (starts internal timer)
    max1.initialise();
    
    //Float value to hold temperature returned
    float fvalue = 0;
    
    while(1) {
        //Check if the chip is ready for a reading to be taken
        if (max1.ready()==1){
            //Get the reading
            fvalue = max1.read_temp();
            
            if (fvalue > 2000){
                if(fvalue==2001){
                    printf("No TC");
                }else if(fvalue==2002){
                    printf("Short to GND");
                }else if(fvalue==2004){
                    printf("Short to VCC");
                }
            }else{
                printf("Temperature is: %f\n\r", fvalue);
            }
     }
        
        //Heartbeat signal (not necessary)
        myled = !myled;
        
        //Delay is not required, here simply for test program
        wait(0.25);
    }
}

Fault Codes:

  • 1 (return value of 2001) - No Thermocouple detected
  • 2 (return value of 2002) - Thermocouple short to GND
  • 4 (return value of 2004) - Thermocouple short to VCC
Committer:
Stavlin
Date:
Tue Oct 23 10:51:21 2012 +0000
Revision:
1:5eeee89cb281
Parent:
0:656c522152d4
Fixed fault reporting. Returns a value of 2000 + fault code on error.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Stavlin 0:656c522152d4 1 #ifndef MAX31855_h
Stavlin 0:656c522152d4 2 #define MAX31855_h
Stavlin 0:656c522152d4 3
Stavlin 0:656c522152d4 4 #include "mbed.h"
Stavlin 0:656c522152d4 5
Stavlin 0:656c522152d4 6 class max31855
Stavlin 0:656c522152d4 7 {
Stavlin 0:656c522152d4 8 SPI& spi;
Stavlin 0:656c522152d4 9 DigitalOut ncs;
Stavlin 0:656c522152d4 10 Timer pollTimer;
Stavlin 0:656c522152d4 11 public:
Stavlin 0:656c522152d4 12
Stavlin 0:656c522152d4 13 max31855(SPI& _spi, PinName _ncs);
Stavlin 0:656c522152d4 14 void select();
Stavlin 0:656c522152d4 15 void deselect();
Stavlin 1:5eeee89cb281 16 void initialise(int setType=0);
Stavlin 0:656c522152d4 17
Stavlin 0:656c522152d4 18 int ready();
Stavlin 1:5eeee89cb281 19 int faultCode;
Stavlin 0:656c522152d4 20
Stavlin 0:656c522152d4 21 float chipTemp;
Stavlin 0:656c522152d4 22 float read_temp();
Stavlin 0:656c522152d4 23 private:
Stavlin 0:656c522152d4 24 PinName _CS_pin;
Stavlin 0:656c522152d4 25 PinName _SO_pin;
Stavlin 0:656c522152d4 26 PinName _SCK_pin;
Stavlin 0:656c522152d4 27 int _units;
Stavlin 0:656c522152d4 28 float _error;
Stavlin 0:656c522152d4 29 };
Stavlin 0:656c522152d4 30
Stavlin 0:656c522152d4 31 #endif