Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of max6675 by
max6675.cpp@4:b674a4cf4584, 2017-10-16 (annotated)
- Committer:
- sandrosole
- Date:
- Mon Oct 16 19:43:20 2017 +0000
- Revision:
- 4:b674a4cf4584
- Parent:
- 2:661ac326e3b3
compatibility change
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| tecnosys | 2:661ac326e3b3 | 1 | |
| tecnosys | 2:661ac326e3b3 | 2 | #include <mbed.h> |
| tecnosys | 2:661ac326e3b3 | 3 | #include "max6675.h" |
| tecnosys | 2:661ac326e3b3 | 4 | |
| tecnosys | 2:661ac326e3b3 | 5 | max6675::max6675(SPI& _spi, PinName _ncs) : spi(_spi), ncs(_ncs) { |
| tecnosys | 2:661ac326e3b3 | 6 | |
| tecnosys | 2:661ac326e3b3 | 7 | } |
| tecnosys | 2:661ac326e3b3 | 8 | |
| tecnosys | 2:661ac326e3b3 | 9 | float max6675::read_temp() { |
| tecnosys | 2:661ac326e3b3 | 10 | short value = 0; |
| tecnosys | 2:661ac326e3b3 | 11 | float temp = 0; |
| tecnosys | 2:661ac326e3b3 | 12 | |
| tecnosys | 2:661ac326e3b3 | 13 | uint8_t highByte=0; |
| tecnosys | 2:661ac326e3b3 | 14 | uint8_t lowByte=0; |
| tecnosys | 2:661ac326e3b3 | 15 | |
| tecnosys | 2:661ac326e3b3 | 16 | select(); |
| tecnosys | 2:661ac326e3b3 | 17 | wait(.25); //This delay is needed else it does'nt seem to update the temp |
| tecnosys | 2:661ac326e3b3 | 18 | |
| tecnosys | 2:661ac326e3b3 | 19 | highByte = spi.write(0); |
| tecnosys | 2:661ac326e3b3 | 20 | lowByte = spi.write(0); |
| tecnosys | 2:661ac326e3b3 | 21 | deselect(); |
| tecnosys | 2:661ac326e3b3 | 22 | |
| tecnosys | 2:661ac326e3b3 | 23 | |
| tecnosys | 2:661ac326e3b3 | 24 | if (lowByte & (1<<2)) { |
| tecnosys | 2:661ac326e3b3 | 25 | error("No Probe"); |
| tecnosys | 2:661ac326e3b3 | 26 | } else { |
| tecnosys | 2:661ac326e3b3 | 27 | value = (highByte << 5 | lowByte>>3); |
| tecnosys | 2:661ac326e3b3 | 28 | } |
| tecnosys | 2:661ac326e3b3 | 29 | |
| tecnosys | 2:661ac326e3b3 | 30 | temp = (value*0.25); // Multiply the value by 0.25 to get temp in ˚C or |
| tecnosys | 2:661ac326e3b3 | 31 | // * (9.0/5.0)) + 32.0; // Convert value to ˚F (ensure proper floats!) |
| tecnosys | 2:661ac326e3b3 | 32 | |
| tecnosys | 2:661ac326e3b3 | 33 | return temp; |
| tecnosys | 2:661ac326e3b3 | 34 | } |
| tecnosys | 2:661ac326e3b3 | 35 | |
| tecnosys | 2:661ac326e3b3 | 36 | void max6675::select() { |
| tecnosys | 2:661ac326e3b3 | 37 | ncs = 0; |
| tecnosys | 2:661ac326e3b3 | 38 | } |
| tecnosys | 2:661ac326e3b3 | 39 | |
| tecnosys | 2:661ac326e3b3 | 40 | void max6675::deselect() { |
| tecnosys | 2:661ac326e3b3 | 41 | ncs = 1; |
| tecnosys | 2:661ac326e3b3 | 42 | } |
