MAX31855 Cold-Junction Compensated Thermocouple-to-Digital Converter
Diff: MAX31855.cpp
- Revision:
- 0:cd9dd4f2c484
- Child:
- 1:aa96d283eead
diff -r 000000000000 -r cd9dd4f2c484 MAX31855.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MAX31855.cpp Tue Sep 09 08:17:42 2014 +0000 @@ -0,0 +1,74 @@ +#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; + +} \ No newline at end of file