ss

Dependencies:   mbed MPU6050

Committer:
SantiagoE
Date:
Mon Feb 22 19:24:30 2021 +0000
Revision:
0:ac37887d5bb2
ss

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SantiagoE 0:ac37887d5bb2 1
SantiagoE 0:ac37887d5bb2 2 #include <mbed.h>
SantiagoE 0:ac37887d5bb2 3 #include "max6675_2.h"
SantiagoE 0:ac37887d5bb2 4
SantiagoE 0:ac37887d5bb2 5 max6675_2::max6675_2(SPI& _spi_2, PinName _ncs_2) : spi_2(_spi_2), ncs_2(_ncs_2) {
SantiagoE 0:ac37887d5bb2 6
SantiagoE 0:ac37887d5bb2 7 }
SantiagoE 0:ac37887d5bb2 8
SantiagoE 0:ac37887d5bb2 9 float max6675_2::read_temp_2() {
SantiagoE 0:ac37887d5bb2 10 short value_2 = 0;
SantiagoE 0:ac37887d5bb2 11 float temp_2 = 0;
SantiagoE 0:ac37887d5bb2 12
SantiagoE 0:ac37887d5bb2 13 uint8_t highByte_2=0;
SantiagoE 0:ac37887d5bb2 14 uint8_t lowByte_2=0;
SantiagoE 0:ac37887d5bb2 15
SantiagoE 0:ac37887d5bb2 16 select_2();
SantiagoE 0:ac37887d5bb2 17 wait(.25); //This delay is needed else it does'nt seem to update the temp
SantiagoE 0:ac37887d5bb2 18
SantiagoE 0:ac37887d5bb2 19 highByte_2 = spi_2.write(0);
SantiagoE 0:ac37887d5bb2 20 lowByte_2 = spi_2.write(0);
SantiagoE 0:ac37887d5bb2 21 deselect_2();
SantiagoE 0:ac37887d5bb2 22
SantiagoE 0:ac37887d5bb2 23
SantiagoE 0:ac37887d5bb2 24 if (lowByte_2 & (1<<2)) {
SantiagoE 0:ac37887d5bb2 25 error("No Probe");
SantiagoE 0:ac37887d5bb2 26 } else {
SantiagoE 0:ac37887d5bb2 27 value_2 = (highByte_2 << 5 | lowByte_2>>3);
SantiagoE 0:ac37887d5bb2 28 }
SantiagoE 0:ac37887d5bb2 29
SantiagoE 0:ac37887d5bb2 30 temp_2 = (value_2*0.25); // Multiply the value by 0.25 to get temp in ˚C or
SantiagoE 0:ac37887d5bb2 31 // * (9.0/5.0)) + 32.0; // Convert value to ˚F (ensure proper floats!)
SantiagoE 0:ac37887d5bb2 32
SantiagoE 0:ac37887d5bb2 33 return temp_2;
SantiagoE 0:ac37887d5bb2 34 }
SantiagoE 0:ac37887d5bb2 35
SantiagoE 0:ac37887d5bb2 36 void max6675_2::select_2() {
SantiagoE 0:ac37887d5bb2 37 ncs_2 = 0;
SantiagoE 0:ac37887d5bb2 38 }
SantiagoE 0:ac37887d5bb2 39
SantiagoE 0:ac37887d5bb2 40 void max6675_2::deselect_2() {
SantiagoE 0:ac37887d5bb2 41 ncs_2 = 1;
SantiagoE 0:ac37887d5bb2 42 }