Maxim MAX6675 Cold-Junction-Compensated K-Thermocoupleto-Digital Converter (0°C to +1024°C) os2 and os5
Dependents: proyectoprueba3 proyectoRTOS proyectoRTOS2 proyectoRTOS ... more
max6675.cpp@0:7c1c768af92a, 2019-05-09 (annotated)
- Committer:
- star297
- Date:
- Thu May 09 22:17:49 2019 +0000
- Revision:
- 0:7c1c768af92a
- Child:
- 2:74731b8476a0
Initial revision
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
star297 | 0:7c1c768af92a | 1 | |
star297 | 0:7c1c768af92a | 2 | #include "max6675.h" |
star297 | 0:7c1c768af92a | 3 | |
star297 | 0:7c1c768af92a | 4 | max6675::max6675(PinName miso, PinName sclk, PinName cs) : |
star297 | 0:7c1c768af92a | 5 | max(NC, miso, sclk), _cs(cs) |
star297 | 0:7c1c768af92a | 6 | { |
star297 | 0:7c1c768af92a | 7 | max.format(16,1); // set 16 bit SPI format |
star297 | 0:7c1c768af92a | 8 | max.frequency(4000000); |
star297 | 0:7c1c768af92a | 9 | } |
star297 | 0:7c1c768af92a | 10 | float max6675::gettemp(int cf) |
star297 | 0:7c1c768af92a | 11 | { |
star297 | 0:7c1c768af92a | 12 | float temp = 0; |
star297 | 0:7c1c768af92a | 13 | int tempByte= 0; |
star297 | 0:7c1c768af92a | 14 | |
star297 | 0:7c1c768af92a | 15 | _cs = 0; |
star297 | 0:7c1c768af92a | 16 | wait_us(1); // wait to stablize |
star297 | 0:7c1c768af92a | 17 | tempByte = max.write(0); |
star297 | 0:7c1c768af92a | 18 | wait_us(1); // wait to finish |
star297 | 0:7c1c768af92a | 19 | _cs = 1; |
star297 | 0:7c1c768af92a | 20 | |
star297 | 0:7c1c768af92a | 21 | if (tempByte & (1<<2)) { // faulty or no sensor connected |
star297 | 0:7c1c768af92a | 22 | return -99; |
star297 | 0:7c1c768af92a | 23 | } else { |
star297 | 0:7c1c768af92a | 24 | temp = (tempByte)/32.0f; |
star297 | 0:7c1c768af92a | 25 | } |
star297 | 0:7c1c768af92a | 26 | if(cf) { |
star297 | 0:7c1c768af92a | 27 | temp = (temp*9.0f/5.0f) + 32.0f; // Convert value to ˚F |
star297 | 0:7c1c768af92a | 28 | } |
star297 | 0:7c1c768af92a | 29 | return temp; |
star297 | 0:7c1c768af92a | 30 | } |