Paul Staron / max6675

Dependents:   proyectoprueba3 proyectoRTOS proyectoRTOS2 proyectoRTOS ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers max6675.cpp Source File

max6675.cpp

00001 
00002 #include "max6675.h"
00003 
00004 max6675::max6675(PinName miso, PinName sclk, PinName cs) :
00005     max(NC, miso, sclk), _cs(cs)
00006 {
00007     max.format(16,1);   // set 16 bit SPI format
00008     max.frequency(400000);
00009 }
00010 
00011 float max6675::gettemp(int cf)
00012 {
00013     float temp  = 0;
00014     int tempByte= 0;
00015     
00016     _cs = 0;
00017     wait_us(1);     // wait to stablize
00018     tempByte  =  max.write(0);
00019     wait_us(1);     // wait to finish
00020     _cs = 1;
00021 
00022     if (tempByte & (1<<2)) { // faulty or no sensor connected
00023         return -99;
00024     } else {
00025         temp = (tempByte)/32.0f;
00026     }
00027     if(cf) {
00028         temp = (temp*9.0f/5.0f) + 32.0f; // Convert value to ˚F
00029     }
00030     return temp;
00031 }