Sample program for the MAX31855. Prints out the temperature read to console.

Dependencies:   MAX31855 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "max31855.h"
00003 
00004 DigitalOut myled(LED1);
00005 
00006 //----------------------------------------------------------
00007 //SPI Interfaces
00008 SPI testSPI(p11,p12,p13);
00009 //----------------------------------------------------------
00010 
00011 //----------------------------------------------------------
00012 //Thermocouples
00013 max31855 max1(testSPI,p21);
00014 //----------------------------------------------------------
00015 
00016 int main() {
00017     //Initialise chip (starts internal timer)
00018     max1.initialise();
00019     
00020     //Float value to hold temperature returned
00021     float fvalue = 0;
00022     
00023     while(1) {
00024         //Check if the chip is ready for a reading to be taken
00025         if (max1.ready()==1){
00026             //Get the reading
00027             fvalue = max1.read_temp();
00028             
00029             if (fvalue > 2000){
00030                 if(fvalue==2001){
00031                     printf("No TC");
00032                 }else if(fvalue==2002){
00033                     printf("Short to Ground");
00034                 }else if(fvalue==2004){
00035                     printf("Short to VCC");
00036                 }
00037             }else{
00038                 printf("Temperature is: %f\n\r", fvalue);
00039             }
00040      }
00041         
00042         //Heartbeat signal (not necessary)
00043         myled = !myled;
00044         
00045         //Delay is not required, here simply for test program
00046         wait(0.25);
00047     }
00048 }