improved MAX31855 Library with errorchecking
Fork of MAX31855 by
Revision 4:064382cf8d8e, committed 2016-01-07
- Comitter:
- nielsvanmegen
- Date:
- Thu Jan 07 09:47:13 2016 +0000
- Parent:
- 3:e2731f1e595b
- Commit message:
- added functionality;
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 e2731f1e595b -r 064382cf8d8e max31855.cpp --- a/max31855.cpp Thu Jan 07 09:24:49 2016 +0000 +++ b/max31855.cpp Thu Jan 07 09:47:13 2016 +0000 @@ -16,37 +16,33 @@ //Variables to hold chip temperature and device status uint8_t tempChipHigh=0; uint8_t tempChipLow=0; - if (_pollTimer.read_ms() > 250) { - //Set CS to initiate transfer and stop conversion - select(thermo); - //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); - //Set the chip temperature - _chipTemp = (tempChipHigh<<4 | tempChipLow>>4)*0.0625; - //Set CS to stop transfer and restart conversion - deselect(thermo); - if (CHECK_BIT(tempProbeLow, 0)) { - //not connected error - if(CHECK_BIT(tempChipLow, 0))return -2; - //short to ground - else if(CHECK_BIT(tempChipLow, 1))return -3; - //short to VCC - else if(CHECK_BIT(tempChipLow, 2))return -4; - else return -5; - } 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; - } + //Set CS to initiate transfer and stop conversion + select(thermo); + //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); + //Set the chip temperature + _chipTemp = (tempChipHigh<<4 | tempChipLow>>4)*0.0625; + //Set CS to stop transfer and restart conversion + deselect(thermo); + if (CHECK_BIT(tempProbeLow, 0)) { + //not connected error + if(CHECK_BIT(tempChipLow, 0))return -2; + //short to ground + else if(CHECK_BIT(tempChipLow, 1))return -3; + //short to VCC + else if(CHECK_BIT(tempChipLow, 2))return -4; + else return -5; } else { - return 8; + //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; } } @@ -73,9 +69,9 @@ _faultCode=0; } -int max31855::ready() +bool max31855::ready() { //Check to see if conversion is complete - if(_pollTimer.read_ms() > _readInterval ) return 1; - else return 0; + if(_pollTimer.read_ms() > _readInterval ) return true; + else return false; } \ No newline at end of file
diff -r e2731f1e595b -r 064382cf8d8e max31855.h --- a/max31855.h Thu Jan 07 09:24:49 2016 +0000 +++ b/max31855.h Thu Jan 07 09:47:13 2016 +0000 @@ -14,7 +14,7 @@ } THERMOCOUPLES; max31855(SPI& _spi, PinName _ncs1, PinName _ncs2); - int ready(); + bool ready(); float read_temp(THERMOCOUPLES thermo); void initialise(uint32_t interval);