Library for MAX31855. Based on MAX6675 library. I have only implemented the temperature reading. The chip supports also the reading of internal reference temperature and faults for shorted thermocouple and shorts to vcc/gnd.

Files at this revision

API Documentation at this revision

Comitter:
ratsept
Date:
Sat Mar 10 19:30:40 2012 +0000
Commit message:

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX31855.cpp	Sat Mar 10 19:30:40 2012 +0000
@@ -0,0 +1,46 @@
+#include <mbed.h>
+#include "MAX31855.h"
+ 
+ MAX31855::MAX31855(SPI& _spi, PinName _ncs) : spi(_spi), ncs(_ncs)
+{
+    deselect();
+}
+ 
+float MAX31855::read_temp()
+{
+    short value = 0;
+    float temp = 0;
+     
+    int16_t response = 0;
+    uint8_t resp_byte = 0;
+     
+    select();
+ 
+    resp_byte = spi.write(0);
+    response |= resp_byte << 8;
+    resp_byte = spi.write(0);
+    response |= resp_byte << 0;
+
+    deselect();
+ 
+    if (response & 0x0001)
+    {
+        error("Error");
+        return 2000.0;
+    }
+    
+    response &= 0xfffc; // mask lower two bits
+    temp = response / 16.0;
+
+    return temp;
+}
+ 
+void MAX31855::select()
+{
+    ncs = 0;
+}
+ 
+void MAX31855::deselect()
+{
+    ncs = 1;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX31855.h	Sat Mar 10 19:30:40 2012 +0000
@@ -0,0 +1,25 @@
+#ifndef MAX31855_h
+#define MAX31855_h
+ 
+#include "mbed.h"
+
+class MAX31855
+{
+    SPI& spi;
+    DigitalOut ncs;
+    public:
+
+    MAX31855(SPI& _spi, PinName _ncs);
+    void select();
+    void deselect();
+     
+    float read_temp();
+    private:
+    PinName _CS_pin;
+    PinName _SO_pin;
+    PinName _SCK_pin;
+    int _units;
+    float _error;
+};
+ 
+#endif
\ No newline at end of file