MAX31855 Cold-Junction Compensated Thermocouple-to-Digital Converter

MAX31855.cpp

Committer:
mederic
Date:
2014-09-09
Revision:
0:cd9dd4f2c484
Child:
1:aa96d283eead

File content as of revision 0:cd9dd4f2c484:

#include "MAX31855.h"

//***********************************/************************************
//                         Constructors                                 //
//***********************************/************************************
MAX31855::MAX31855(PinName mosi, PinName miso, PinName sck, PinName ncs) :_spi(mosi,miso,sck), _ncs(ncs)
{
    _ncs = 1;   //CS high
    _spi.format(16,0);
    _spi.frequency(1000000);
}

//***********************************/************************************
//                                Get Set                               //
//***********************************/************************************
bool MAX31855::opened(void)
{
    read();
    return _oc;
}

bool MAX31855::fault(void)
{
    read();
    return _fault;
}

bool MAX31855::scToVcc(void)
{
    read();
    return _scv;
}

bool MAX31855::scToGnd(void)
{
    read();
    return _scg;
}



//***********************************/************************************
//                             Public Methods                           //
//***********************************/************************************
float MAX31855::thermocouple(void)
{
    read();
    return _t;
}

float MAX31855::chip(void)
{
    read();
    return _chip_t;
}
    
//***********************************/************************************
//                             Protected Methods                        //
//***********************************/************************************
void MAX31855::read(void)
{
    _ncs = 0;
    unsigned short high = _spi.write(0);
    unsigned short  low = _spi.write(0);
    _ncs = 1;
    
    _t = (high>>2)/4.0;
    _chip_t = (low>>4)/16.0;
    _fault = high&0x01;
    _scv = low&0x04;
    _scg = low&0x02;
    _oc = low&0x01;
    
}