MAX31855 Cold-Junction Compensated Thermocouple-to-Digital Converter

Committer:
mederic
Date:
Tue Sep 09 08:17:42 2014 +0000
Revision:
0:cd9dd4f2c484
Child:
1:aa96d283eead
first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mederic 0:cd9dd4f2c484 1 #include "MAX31855.h"
mederic 0:cd9dd4f2c484 2
mederic 0:cd9dd4f2c484 3 //***********************************/************************************
mederic 0:cd9dd4f2c484 4 // Constructors //
mederic 0:cd9dd4f2c484 5 //***********************************/************************************
mederic 0:cd9dd4f2c484 6 MAX31855::MAX31855(PinName mosi, PinName miso, PinName sck, PinName ncs) :_spi(mosi,miso,sck), _ncs(ncs)
mederic 0:cd9dd4f2c484 7 {
mederic 0:cd9dd4f2c484 8 _ncs = 1; //CS high
mederic 0:cd9dd4f2c484 9 _spi.format(16,0);
mederic 0:cd9dd4f2c484 10 _spi.frequency(1000000);
mederic 0:cd9dd4f2c484 11 }
mederic 0:cd9dd4f2c484 12
mederic 0:cd9dd4f2c484 13 //***********************************/************************************
mederic 0:cd9dd4f2c484 14 // Get Set //
mederic 0:cd9dd4f2c484 15 //***********************************/************************************
mederic 0:cd9dd4f2c484 16 bool MAX31855::opened(void)
mederic 0:cd9dd4f2c484 17 {
mederic 0:cd9dd4f2c484 18 read();
mederic 0:cd9dd4f2c484 19 return _oc;
mederic 0:cd9dd4f2c484 20 }
mederic 0:cd9dd4f2c484 21
mederic 0:cd9dd4f2c484 22 bool MAX31855::fault(void)
mederic 0:cd9dd4f2c484 23 {
mederic 0:cd9dd4f2c484 24 read();
mederic 0:cd9dd4f2c484 25 return _fault;
mederic 0:cd9dd4f2c484 26 }
mederic 0:cd9dd4f2c484 27
mederic 0:cd9dd4f2c484 28 bool MAX31855::scToVcc(void)
mederic 0:cd9dd4f2c484 29 {
mederic 0:cd9dd4f2c484 30 read();
mederic 0:cd9dd4f2c484 31 return _scv;
mederic 0:cd9dd4f2c484 32 }
mederic 0:cd9dd4f2c484 33
mederic 0:cd9dd4f2c484 34 bool MAX31855::scToGnd(void)
mederic 0:cd9dd4f2c484 35 {
mederic 0:cd9dd4f2c484 36 read();
mederic 0:cd9dd4f2c484 37 return _scg;
mederic 0:cd9dd4f2c484 38 }
mederic 0:cd9dd4f2c484 39
mederic 0:cd9dd4f2c484 40
mederic 0:cd9dd4f2c484 41
mederic 0:cd9dd4f2c484 42 //***********************************/************************************
mederic 0:cd9dd4f2c484 43 // Public Methods //
mederic 0:cd9dd4f2c484 44 //***********************************/************************************
mederic 0:cd9dd4f2c484 45 float MAX31855::thermocouple(void)
mederic 0:cd9dd4f2c484 46 {
mederic 0:cd9dd4f2c484 47 read();
mederic 0:cd9dd4f2c484 48 return _t;
mederic 0:cd9dd4f2c484 49 }
mederic 0:cd9dd4f2c484 50
mederic 0:cd9dd4f2c484 51 float MAX31855::chip(void)
mederic 0:cd9dd4f2c484 52 {
mederic 0:cd9dd4f2c484 53 read();
mederic 0:cd9dd4f2c484 54 return _chip_t;
mederic 0:cd9dd4f2c484 55 }
mederic 0:cd9dd4f2c484 56
mederic 0:cd9dd4f2c484 57 //***********************************/************************************
mederic 0:cd9dd4f2c484 58 // Protected Methods //
mederic 0:cd9dd4f2c484 59 //***********************************/************************************
mederic 0:cd9dd4f2c484 60 void MAX31855::read(void)
mederic 0:cd9dd4f2c484 61 {
mederic 0:cd9dd4f2c484 62 _ncs = 0;
mederic 0:cd9dd4f2c484 63 unsigned short high = _spi.write(0);
mederic 0:cd9dd4f2c484 64 unsigned short low = _spi.write(0);
mederic 0:cd9dd4f2c484 65 _ncs = 1;
mederic 0:cd9dd4f2c484 66
mederic 0:cd9dd4f2c484 67 _t = (high>>2)/4.0;
mederic 0:cd9dd4f2c484 68 _chip_t = (low>>4)/16.0;
mederic 0:cd9dd4f2c484 69 _fault = high&0x01;
mederic 0:cd9dd4f2c484 70 _scv = low&0x04;
mederic 0:cd9dd4f2c484 71 _scg = low&0x02;
mederic 0:cd9dd4f2c484 72 _oc = low&0x01;
mederic 0:cd9dd4f2c484 73
mederic 0:cd9dd4f2c484 74 }