![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Sample program for the MAX31855. Prints out the temperature read to console.
main.cpp@0:c50a2801c243, 2012-10-22 (annotated)
- Committer:
- Stavlin
- Date:
- Mon Oct 22 09:42:16 2012 +0000
- Revision:
- 0:c50a2801c243
- Child:
- 1:6bed4f6f7b35
Sample program using the MAX31855 library. Prints of the temperature of one MAX31855 to console.
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 | 0:c50a2801c243 | 29 | printf("Temperature is: %f\n\r", fvalue); |
Stavlin | 0:c50a2801c243 | 30 | } |
Stavlin | 0:c50a2801c243 | 31 | |
Stavlin | 0:c50a2801c243 | 32 | //Heartbeat signal (not necessary) |
Stavlin | 0:c50a2801c243 | 33 | myled = !myled; |
Stavlin | 0:c50a2801c243 | 34 | |
Stavlin | 0:c50a2801c243 | 35 | //Delay is not required, here simply for test program |
Stavlin | 0:c50a2801c243 | 36 | wait(0.25); |
Stavlin | 0:c50a2801c243 | 37 | } |
Stavlin | 0:c50a2801c243 | 38 | } |