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!

Dependents:   elixys

Fork of MAX31855 by Joe Staton

Committer:
henryeherman
Date:
Wed Oct 30 07:05:34 2013 +0000
Revision:
2:b978f1503c27
Parent:
1:5eeee89cb281
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!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Stavlin 1:5eeee89cb281 1
Stavlin 1:5eeee89cb281 2 #include <mbed.h>
Stavlin 1:5eeee89cb281 3 #include "max31855.h"
Stavlin 1:5eeee89cb281 4
henryeherman 2:b978f1503c27 5 max31855::max31855(SPI& _spi, void(*sel)(void), void(*usel)(void)) : spi(_spi) {
henryeherman 2:b978f1503c27 6 selectfxn = sel;
henryeherman 2:b978f1503c27 7 unselectfxn = usel;
henryeherman 2:b978f1503c27 8 initialise(0);
Stavlin 1:5eeee89cb281 9 }
Stavlin 1:5eeee89cb281 10
Stavlin 1:5eeee89cb281 11 float max31855::read_temp() {
Stavlin 1:5eeee89cb281 12 short value = 0;
Stavlin 1:5eeee89cb281 13 float temp = 0;
Stavlin 1:5eeee89cb281 14
Stavlin 1:5eeee89cb281 15 //Variables to hold probe temperature
Stavlin 1:5eeee89cb281 16 uint8_t tempProbeHigh=0;
Stavlin 1:5eeee89cb281 17 uint8_t tempProbeLow=0;
Stavlin 1:5eeee89cb281 18
Stavlin 1:5eeee89cb281 19 //Variables to hold chip temperature and device status
Stavlin 1:5eeee89cb281 20 uint8_t tempChipHigh=0;
Stavlin 1:5eeee89cb281 21 uint8_t tempChipLow=0;
Stavlin 1:5eeee89cb281 22
henryeherman 2:b978f1503c27 23 select();
henryeherman 2:b978f1503c27 24
henryeherman 2:b978f1503c27 25 //Read in Probe tempeature
henryeherman 2:b978f1503c27 26 tempProbeHigh = spi.write(0);
henryeherman 2:b978f1503c27 27 tempProbeLow = spi.write(0);
henryeherman 2:b978f1503c27 28
henryeherman 2:b978f1503c27 29 //Get the chip temperature and the fault data
henryeherman 2:b978f1503c27 30 tempChipHigh = spi.write(0);
henryeherman 2:b978f1503c27 31 tempChipLow = spi.write(0);
Stavlin 1:5eeee89cb281 32
henryeherman 2:b978f1503c27 33 //Set the chip temperature
henryeherman 2:b978f1503c27 34 chipTemp = (tempChipHigh<<4 | tempChipLow>>4)*0.25;
henryeherman 2:b978f1503c27 35
henryeherman 2:b978f1503c27 36 //Set CS to stop transfer and restart conversion
henryeherman 2:b978f1503c27 37 deselect();
henryeherman 2:b978f1503c27 38
henryeherman 2:b978f1503c27 39 //Check for a fault (last bit of transfer is fault bit)
henryeherman 2:b978f1503c27 40 if ((tempProbeLow & 1)==1){
henryeherman 2:b978f1503c27 41 //Chip reports a fault, extract fault from Chip Temperature data
henryeherman 2:b978f1503c27 42 int faultType = (tempChipLow & 7);
Stavlin 1:5eeee89cb281 43
henryeherman 2:b978f1503c27 44 faultCode=faultType;
Stavlin 1:5eeee89cb281 45
henryeherman 2:b978f1503c27 46 return 2000+faultType;
henryeherman 2:b978f1503c27 47 /*if (faultType==1){
henryeherman 2:b978f1503c27 48 //Open circuit (no TC)
henryeherman 2:b978f1503c27 49 return 2000 + faultType;
henryeherman 2:b978f1503c27 50 }else if (faultType==2){
henryeherman 2:b978f1503c27 51 //Short to GND
henryeherman 2:b978f1503c27 52 return 2000 + faultType;
henryeherman 2:b978f1503c27 53 }else if (faultType==4){
henryeherman 2:b978f1503c27 54 //Short to VCC
henryeherman 2:b978f1503c27 55 return 0.4;
Stavlin 1:5eeee89cb281 56 }else{
henryeherman 2:b978f1503c27 57 return 0.5;
henryeherman 2:b978f1503c27 58 }*/
Stavlin 1:5eeee89cb281 59 }else{
henryeherman 2:b978f1503c27 60 //Integer value of temperature
henryeherman 2:b978f1503c27 61 value = (tempProbeHigh<< 6 | tempProbeLow>>2);
henryeherman 2:b978f1503c27 62
henryeherman 2:b978f1503c27 63 //Get actual temperature (last 2 bits of integer are decimal 0.5 and 0.25)
henryeherman 2:b978f1503c27 64 temp = (value*0.25); // Multiply the value by 0.25 to get temp in C or
henryeherman 2:b978f1503c27 65 // * (9.0/5.0)) + 32.0; // Convert value to F (ensure proper floats!)
henryeherman 2:b978f1503c27 66
henryeherman 2:b978f1503c27 67 return temp;
Stavlin 1:5eeee89cb281 68 }
Stavlin 1:5eeee89cb281 69 }
Stavlin 1:5eeee89cb281 70
Stavlin 1:5eeee89cb281 71 void max31855::select() {
Stavlin 1:5eeee89cb281 72 //Set CS low to start transmission (interrupts conversion)
henryeherman 2:b978f1503c27 73 //ncs = 0;
henryeherman 2:b978f1503c27 74 selectfxn();
Stavlin 1:5eeee89cb281 75 }
Stavlin 1:5eeee89cb281 76
Stavlin 1:5eeee89cb281 77 void max31855::deselect() {
Stavlin 1:5eeee89cb281 78 //Set CS high to stop transmission (restarts conversion)
henryeherman 2:b978f1503c27 79 //ncs = 1;
henryeherman 2:b978f1503c27 80 unselectfxn();
Stavlin 1:5eeee89cb281 81 }
Stavlin 1:5eeee89cb281 82
Stavlin 1:5eeee89cb281 83 void max31855::initialise(int setType) {
henryeherman 2:b978f1503c27 84 //Start the conversion timer
Stavlin 1:5eeee89cb281 85 faultCode=0;
Stavlin 0:656c522152d4 86 }