Fork the MAX31855 library. Allows a fxn to be called to select and unselect the TC. Now using a shift register array we can multiplex a great number of these TC chips!
Fork of MAX31855 by
Revision 2:b978f1503c27, committed 2013-10-30
- Comitter:
- henryeherman
- Date:
- Wed Oct 30 07:05:34 2013 +0000
- Parent:
- 1:5eeee89cb281
- Commit message:
- Fork the MAX31855 library and allow functions to be called before reading the TC values, instead of a digital pin. Allows a shift register to be used to select the TC and a VERY large number of TC can be multiplexed!
Changed in this revision
max31855.cpp | Show annotated file Show diff for this revision Revisions of this file |
max31855.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 5eeee89cb281 -r b978f1503c27 max31855.cpp --- a/max31855.cpp Tue Oct 23 10:51:21 2012 +0000 +++ b/max31855.cpp Wed Oct 30 07:05:34 2013 +0000 @@ -2,8 +2,10 @@ #include <mbed.h> #include "max31855.h" -max31855::max31855(SPI& _spi, PinName _ncs) : spi(_spi), ncs(_ncs) { - +max31855::max31855(SPI& _spi, void(*sel)(void), void(*usel)(void)) : spi(_spi) { + selectfxn = sel; + unselectfxn = usel; + initialise(0); } float max31855::read_temp() { @@ -18,85 +20,67 @@ uint8_t tempChipHigh=0; uint8_t tempChipLow=0; - if (pollTimer.read_ms() > 250){ - //Set CS to initiate transfer and stop conversion - select(); + select(); + + //Read in Probe tempeature + tempProbeHigh = spi.write(0); + tempProbeLow = spi.write(0); + + //Get the chip temperature and the fault data + tempChipHigh = spi.write(0); + tempChipLow = spi.write(0); - //Read in Probe tempeature - tempProbeHigh = spi.write(0); - tempProbeLow = spi.write(0); + //Set the chip temperature + chipTemp = (tempChipHigh<<4 | tempChipLow>>4)*0.25; + + //Set CS to stop transfer and restart conversion + deselect(); + + //Check for a fault (last bit of transfer is fault bit) + if ((tempProbeLow & 1)==1){ + //Chip reports a fault, extract fault from Chip Temperature data + int faultType = (tempChipLow & 7); - //Get the chip temperature and the fault data - tempChipHigh = spi.write(0); - tempChipLow = spi.write(0); - - //Set the chip temperature - chipTemp = (tempChipHigh<<4 | tempChipLow>>4)*0.25; - - //Set CS to stop transfer and restart conversion - deselect(); + faultCode=faultType; - //Check for a fault (last bit of transfer is fault bit) - if ((tempProbeLow & 1)==1){ - //Chip reports a fault, extract fault from Chip Temperature data - int faultType = (tempChipLow & 7); - - faultCode=faultType; - - return 2000+faultType; - /*if (faultType==1){ - //Open circuit (no TC) - return 2000 + faultType; - }else if (faultType==2){ - //Short to GND - return 2000 + faultType; - }else if (faultType==4){ - //Short to VCC - return 0.4; - }else{ - return 0.5; - }*/ + return 2000+faultType; + /*if (faultType==1){ + //Open circuit (no TC) + return 2000 + faultType; + }else if (faultType==2){ + //Short to GND + return 2000 + faultType; + }else if (faultType==4){ + //Short to VCC + return 0.4; }else{ - //Integer value of temperature - value = (tempProbeHigh<< 6 | tempProbeLow>>2); - - //Get actual temperature (last 2 bits of integer are decimal 0.5 and 0.25) - temp = (value*0.25); // Multiply the value by 0.25 to get temp in C or - // * (9.0/5.0)) + 32.0; // Convert value to F (ensure proper floats!) - - return temp; - } + return 0.5; + }*/ }else{ - //Chip not ready for reading - return -1; + //Integer value of temperature + value = (tempProbeHigh<< 6 | tempProbeLow>>2); + + //Get actual temperature (last 2 bits of integer are decimal 0.5 and 0.25) + temp = (value*0.25); // Multiply the value by 0.25 to get temp in C or + // * (9.0/5.0)) + 32.0; // Convert value to F (ensure proper floats!) + + return temp; } } void max31855::select() { //Set CS low to start transmission (interrupts conversion) - ncs = 0; + //ncs = 0; + selectfxn(); } void max31855::deselect() { //Set CS high to stop transmission (restarts conversion) - ncs = 1; - //Reset conversion timer - pollTimer.reset(); + //ncs = 1; + unselectfxn(); } void max31855::initialise(int setType) { - //Start the conversion timer - pollTimer.start(); + //Start the conversion timer faultCode=0; -} - -int max31855::ready() { - //Check to see if conversion is complete - if (pollTimer.read_ms() > 250) { - //Conversion complete - return 1; - }else{ - //Conversion incomplete - return 0; - } } \ No newline at end of file
diff -r 5eeee89cb281 -r b978f1503c27 max31855.h --- a/max31855.h Tue Oct 23 10:51:21 2012 +0000 +++ b/max31855.h Wed Oct 30 07:05:34 2013 +0000 @@ -6,16 +6,17 @@ class max31855 { SPI& spi; - DigitalOut ncs; + void(*selectfxn)(void); + void(*unselectfxn)(void); + //DigitalOut ncs; Timer pollTimer; public: - max31855(SPI& _spi, PinName _ncs); + max31855(SPI& _spi, void(*sel)(void), void(*usel)(void)); void select(); void deselect(); void initialise(int setType=0); - - int ready(); + int faultCode; float chipTemp;