Librería para leer temperatura haciendo comunicación SPI con el integrado MAX6675

Files at this revision

API Documentation at this revision

Comitter:
cristian_junca
Date:
Mon Jun 08 23:18:38 2020 +0000
Commit message:
Read temperatura with SPI communication

Changed in this revision

max6675.cpp Show annotated file Show diff for this revision Revisions of this file
max6675.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 33fb492d139e max6675.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/max6675.cpp	Mon Jun 08 23:18:38 2020 +0000
@@ -0,0 +1,40 @@
+#include "mbed.h"
+#include "max6675.h"
+ 
+max6675::max6675(SPI& _spi, PinName _ss) : spi(_spi), ss(_ss) {
+ 
+}
+ 
+float max6675::read_temp() {
+    short value = 0;
+    float temp = 0;
+    
+    uint8_t highByte=0;
+    uint8_t lowByte=0;
+    
+    select();
+    wait(.25); //This delay is needed else it doesn't seem to update the temp
+ 
+    highByte = spi.write(0);
+    lowByte = spi.write(0);
+    deselect();
+ 
+    if (lowByte & (1<<2)) {
+        error("No Probe");
+    } else {
+        value = (highByte << 5 | lowByte>>3);
+    }
+    
+    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 max6675::select() {
+    ss = 0;
+}
+ 
+void max6675::deselect() {
+    ss = 1;
+}
\ No newline at end of file
diff -r 000000000000 -r 33fb492d139e max6675.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/max6675.h	Mon Jun 08 23:18:38 2020 +0000
@@ -0,0 +1,26 @@
+#ifndef MAX6675_h
+#define MAX6675_h
+ 
+#include "mbed.h"
+ 
+class max6675
+{
+    SPI& spi;
+    DigitalOut ss;
+  public:
+  
+    max6675(SPI& _spi, PinName _ss);
+    
+    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