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

Dependents:   proyectoprueba3 proyectoRTOS proyectoRTOS2 proyectoRTOS ... more

Committer:
star297
Date:
Mon Apr 27 06:43:19 2020 +0000
Revision:
2:74731b8476a0
Parent:
0:7c1c768af92a
update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
star297 0:7c1c768af92a 1
star297 0:7c1c768af92a 2 #include "max6675.h"
star297 0:7c1c768af92a 3
star297 0:7c1c768af92a 4 max6675::max6675(PinName miso, PinName sclk, PinName cs) :
star297 0:7c1c768af92a 5 max(NC, miso, sclk), _cs(cs)
star297 0:7c1c768af92a 6 {
star297 0:7c1c768af92a 7 max.format(16,1); // set 16 bit SPI format
star297 2:74731b8476a0 8 max.frequency(400000);
star297 0:7c1c768af92a 9 }
star297 2:74731b8476a0 10
star297 0:7c1c768af92a 11 float max6675::gettemp(int cf)
star297 0:7c1c768af92a 12 {
star297 0:7c1c768af92a 13 float temp = 0;
star297 0:7c1c768af92a 14 int tempByte= 0;
star297 0:7c1c768af92a 15
star297 0:7c1c768af92a 16 _cs = 0;
star297 0:7c1c768af92a 17 wait_us(1); // wait to stablize
star297 0:7c1c768af92a 18 tempByte = max.write(0);
star297 0:7c1c768af92a 19 wait_us(1); // wait to finish
star297 0:7c1c768af92a 20 _cs = 1;
star297 0:7c1c768af92a 21
star297 0:7c1c768af92a 22 if (tempByte & (1<<2)) { // faulty or no sensor connected
star297 0:7c1c768af92a 23 return -99;
star297 0:7c1c768af92a 24 } else {
star297 0:7c1c768af92a 25 temp = (tempByte)/32.0f;
star297 0:7c1c768af92a 26 }
star297 0:7c1c768af92a 27 if(cf) {
star297 0:7c1c768af92a 28 temp = (temp*9.0f/5.0f) + 32.0f; // Convert value to ˚F
star297 0:7c1c768af92a 29 }
star297 0:7c1c768af92a 30 return temp;
star297 0:7c1c768af92a 31 }