![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Sample program for the MAX31855. Prints out the temperature read to console.
main.cpp@1:6bed4f6f7b35, 2012-10-23 (annotated)
- Committer:
- Stavlin
- Date:
- Tue Oct 23 10:55:17 2012 +0000
- Revision:
- 1:6bed4f6f7b35
- Parent:
- 0:c50a2801c243
Altered to use new fault code setup.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Stavlin | 0:c50a2801c243 | 1 | #include "mbed.h" |
Stavlin | 0:c50a2801c243 | 2 | #include "max31855.h" |
Stavlin | 0:c50a2801c243 | 3 | |
Stavlin | 0:c50a2801c243 | 4 | DigitalOut myled(LED1); |
Stavlin | 0:c50a2801c243 | 5 | |
Stavlin | 0:c50a2801c243 | 6 | //---------------------------------------------------------- |
Stavlin | 0:c50a2801c243 | 7 | //SPI Interfaces |
Stavlin | 0:c50a2801c243 | 8 | SPI testSPI(p11,p12,p13); |
Stavlin | 0:c50a2801c243 | 9 | //---------------------------------------------------------- |
Stavlin | 0:c50a2801c243 | 10 | |
Stavlin | 0:c50a2801c243 | 11 | //---------------------------------------------------------- |
Stavlin | 0:c50a2801c243 | 12 | //Thermocouples |
Stavlin | 0:c50a2801c243 | 13 | max31855 max1(testSPI,p21); |
Stavlin | 0:c50a2801c243 | 14 | //---------------------------------------------------------- |
Stavlin | 0:c50a2801c243 | 15 | |
Stavlin | 0:c50a2801c243 | 16 | int main() { |
Stavlin | 0:c50a2801c243 | 17 | //Initialise chip (starts internal timer) |
Stavlin | 0:c50a2801c243 | 18 | max1.initialise(); |
Stavlin | 0:c50a2801c243 | 19 | |
Stavlin | 0:c50a2801c243 | 20 | //Float value to hold temperature returned |
Stavlin | 0:c50a2801c243 | 21 | float fvalue = 0; |
Stavlin | 0:c50a2801c243 | 22 | |
Stavlin | 0:c50a2801c243 | 23 | while(1) { |
Stavlin | 0:c50a2801c243 | 24 | //Check if the chip is ready for a reading to be taken |
Stavlin | 0:c50a2801c243 | 25 | if (max1.ready()==1){ |
Stavlin | 0:c50a2801c243 | 26 | //Get the reading |
Stavlin | 0:c50a2801c243 | 27 | fvalue = max1.read_temp(); |
Stavlin | 0:c50a2801c243 | 28 | |
Stavlin | 1:6bed4f6f7b35 | 29 | if (fvalue > 2000){ |
Stavlin | 1:6bed4f6f7b35 | 30 | if(fvalue==2001){ |
Stavlin | 1:6bed4f6f7b35 | 31 | printf("No TC"); |
Stavlin | 1:6bed4f6f7b35 | 32 | }else if(fvalue==2002){ |
Stavlin | 1:6bed4f6f7b35 | 33 | printf("Short to Ground"); |
Stavlin | 1:6bed4f6f7b35 | 34 | }else if(fvalue==2004){ |
Stavlin | 1:6bed4f6f7b35 | 35 | printf("Short to VCC"); |
Stavlin | 1:6bed4f6f7b35 | 36 | } |
Stavlin | 1:6bed4f6f7b35 | 37 | }else{ |
Stavlin | 1:6bed4f6f7b35 | 38 | printf("Temperature is: %f\n\r", fvalue); |
Stavlin | 1:6bed4f6f7b35 | 39 | } |
Stavlin | 1:6bed4f6f7b35 | 40 | } |
Stavlin | 0:c50a2801c243 | 41 | |
Stavlin | 0:c50a2801c243 | 42 | //Heartbeat signal (not necessary) |
Stavlin | 0:c50a2801c243 | 43 | myled = !myled; |
Stavlin | 0:c50a2801c243 | 44 | |
Stavlin | 0:c50a2801c243 | 45 | //Delay is not required, here simply for test program |
Stavlin | 0:c50a2801c243 | 46 | wait(0.25); |
Stavlin | 0:c50a2801c243 | 47 | } |
Stavlin | 0:c50a2801c243 | 48 | } |