BMS_T2

Dependencies:   INA226

Committer:
takuma1
Date:
Tue Oct 13 06:26:34 2020 +0000
Revision:
2:3bbbe439ec11
BMS_NO_CAN;

Who changed what in which revision?

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