Jason Engelman
/
max6675
Revision 0:b49d36e03092, committed 2010-05-15
- Comitter:
- tecnosys
- Date:
- Sat May 15 06:26:05 2010 +0000
- Child:
- 1:9274ae9e3938
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat May 15 06:26:05 2010 +0000 @@ -0,0 +1,22 @@ +#include "mbed.h" +#include "max6675.h" + + +SPI spi(p11,p12,p13); + +max6675 max(spi,p18); +Serial pc(USBTX,USBRX); + +int main() { + + + while (1) { + + float temp = max.read_temp(); + printf("\n\rT: %f",temp ); + + wait(.25); + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max6675.cpp Sat May 15 06:26:05 2010 +0000 @@ -0,0 +1,42 @@ + +#include <mbed.h> +#include "max6675.h" + +max6675::max6675(SPI& _spi, PinName _ncs) : spi(_spi), ncs(_ncs) { + +} + +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 does'nt seem to update the temp + + highByte = spi.write(0); + lowByte = spi.write(0); + deselect(); + + + if (lowByte & (1<<2)) { + printf("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() { + ncs = 0; +} + +void max6675::deselect() { + ncs = 1; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max6675.h Sat May 15 06:26:05 2010 +0000 @@ -0,0 +1,25 @@ +#ifndef MAX6675_h +#define MAX6675_h + +#include "mbed.h" + +class max6675 +{ + SPI& spi; + DigitalOut ncs; + public: + + max6675(SPI& _spi, PinName _ncs); + void select(); + void deselect(); + + float read_temp(); + private: + PinName _CS_pin; + PinName _SO_pin; + PinName _SCK_pin; + int _units; + float _error; +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat May 15 06:26:05 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/49a220cc26e0