Maxim MAX6675 Cold-Junction-Compensated K-Thermocoupleto-Digital Converter (0°C to +1024°C) os2 and os5

Dependents:   proyectoprueba3 proyectoRTOS proyectoRTOS2 proyectoRTOS ... more

Revision:
0:7c1c768af92a
Child:
2:74731b8476a0
diff -r 000000000000 -r 7c1c768af92a max6675.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/max6675.cpp	Thu May 09 22:17:49 2019 +0000
@@ -0,0 +1,30 @@
+
+#include "max6675.h"
+
+max6675::max6675(PinName miso, PinName sclk, PinName cs) :
+    max(NC, miso, sclk), _cs(cs)
+{
+    max.format(16,1);   // set 16 bit SPI format
+    max.frequency(4000000);
+}
+float max6675::gettemp(int cf)
+{
+    float temp  = 0;
+    int tempByte= 0;
+    
+    _cs = 0;
+    wait_us(1);     // wait to stablize
+    tempByte  =  max.write(0);
+    wait_us(1);     // wait to finish
+    _cs = 1;
+
+    if (tempByte & (1<<2)) { // faulty or no sensor connected
+        return -99;
+    } else {
+        temp = (tempByte)/32.0f;
+    }
+    if(cf) {
+        temp = (temp*9.0f/5.0f) + 32.0f; // Convert value to ˚F
+    }
+    return temp;
+}