Quick & dirty port of the Adafruit library for their MAX31865 temperature sensor board. It is designed to be used with the swspi library which in turn is designed to be used on the MAX32630FTHR board.

Dependents:   Rocket

Committer:
danjulio
Date:
Sun Jun 11 04:00:56 2017 +0000
Revision:
0:9294dd756a0c
Initial commit of max31865 ported to mbed with swspi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
danjulio 0:9294dd756a0c 1 /***************************************************
danjulio 0:9294dd756a0c 2 This is a library for the Adafruit PT100/P1000 RTD Sensor w/MAX31865
danjulio 0:9294dd756a0c 3
danjulio 0:9294dd756a0c 4 Designed specifically to work with the Adafruit RTD Sensor
danjulio 0:9294dd756a0c 5 ----> https://www.adafruit.com/products/3328
danjulio 0:9294dd756a0c 6
danjulio 0:9294dd756a0c 7 This sensor uses SPI to communicate, 4 pins are required to
danjulio 0:9294dd756a0c 8 interface
danjulio 0:9294dd756a0c 9 Adafruit invests time and resources providing this open source code,
danjulio 0:9294dd756a0c 10 please support Adafruit and open-source hardware by purchasing
danjulio 0:9294dd756a0c 11 products from Adafruit!
danjulio 0:9294dd756a0c 12
danjulio 0:9294dd756a0c 13 Written by Limor Fried/Ladyada for Adafruit Industries.
danjulio 0:9294dd756a0c 14 BSD license, all text above must be included in any redistribution
danjulio 0:9294dd756a0c 15
danjulio 0:9294dd756a0c 16 Modified for mbed project - Dan Julio - 5/2017
danjulio 0:9294dd756a0c 17 ****************************************************/
danjulio 0:9294dd756a0c 18 #ifndef ADAFRUIT_MAX31865_H
danjulio 0:9294dd756a0c 19 #define ADAFRUIT_MAX31865_H
danjulio 0:9294dd756a0c 20
danjulio 0:9294dd756a0c 21 #include <stdint.h>
danjulio 0:9294dd756a0c 22 #include "mbed.h"
danjulio 0:9294dd756a0c 23 #include "swspi.h"
danjulio 0:9294dd756a0c 24
danjulio 0:9294dd756a0c 25 #define MAX31865_CONFIG_REG 0x00
danjulio 0:9294dd756a0c 26 #define MAX31865_CONFIG_BIAS 0x80
danjulio 0:9294dd756a0c 27 #define MAX31865_CONFIG_MODEAUTO 0x40
danjulio 0:9294dd756a0c 28 #define MAX31865_CONFIG_MODEOFF 0x00
danjulio 0:9294dd756a0c 29 #define MAX31865_CONFIG_1SHOT 0x20
danjulio 0:9294dd756a0c 30 #define MAX31865_CONFIG_3WIRE 0x10
danjulio 0:9294dd756a0c 31 #define MAX31865_CONFIG_24WIRE 0x00
danjulio 0:9294dd756a0c 32 #define MAX31865_CONFIG_FAULTSTAT 0x02
danjulio 0:9294dd756a0c 33 #define MAX31865_CONFIG_FILT50HZ 0x01
danjulio 0:9294dd756a0c 34 #define MAX31865_CONFIG_FILT60HZ 0x00
danjulio 0:9294dd756a0c 35
danjulio 0:9294dd756a0c 36 #define MAX31865_RTDMSB_REG 0x01
danjulio 0:9294dd756a0c 37 #define MAX31865_RTDLSB_REG 0x02
danjulio 0:9294dd756a0c 38 #define MAX31865_HFAULTMSB_REG 0x03
danjulio 0:9294dd756a0c 39 #define MAX31865_HFAULTLSB_REG 0x04
danjulio 0:9294dd756a0c 40 #define MAX31865_LFAULTMSB_REG 0x05
danjulio 0:9294dd756a0c 41 #define MAX31865_LFAULTLSB_REG 0x06
danjulio 0:9294dd756a0c 42 #define MAX31865_FAULTSTAT_REG 0x07
danjulio 0:9294dd756a0c 43
danjulio 0:9294dd756a0c 44
danjulio 0:9294dd756a0c 45 #define MAX31865_FAULT_HIGHTHRESH 0x80
danjulio 0:9294dd756a0c 46 #define MAX31865_FAULT_LOWTHRESH 0x40
danjulio 0:9294dd756a0c 47 #define MAX31865_FAULT_REFINLOW 0x20
danjulio 0:9294dd756a0c 48 #define MAX31865_FAULT_REFINHIGH 0x10
danjulio 0:9294dd756a0c 49 #define MAX31865_FAULT_RTDINLOW 0x08
danjulio 0:9294dd756a0c 50 #define MAX31865_FAULT_OVUV 0x04
danjulio 0:9294dd756a0c 51
danjulio 0:9294dd756a0c 52
danjulio 0:9294dd756a0c 53 #define RTD_A 3.9083e-3
danjulio 0:9294dd756a0c 54 #define RTD_B -5.775e-7
danjulio 0:9294dd756a0c 55
danjulio 0:9294dd756a0c 56 typedef enum max31865_numwires {
danjulio 0:9294dd756a0c 57 MAX31865_2WIRE = 0,
danjulio 0:9294dd756a0c 58 MAX31865_3WIRE = 1,
danjulio 0:9294dd756a0c 59 MAX31865_4WIRE = 0
danjulio 0:9294dd756a0c 60 } max31865_numwires_t;
danjulio 0:9294dd756a0c 61
danjulio 0:9294dd756a0c 62
danjulio 0:9294dd756a0c 63 class Adafruit_MAX31865 {
danjulio 0:9294dd756a0c 64 public:
danjulio 0:9294dd756a0c 65 Adafruit_MAX31865(swspi& spiO, int ssNum, PinName rdyPin);
danjulio 0:9294dd756a0c 66
danjulio 0:9294dd756a0c 67 bool begin(max31865_numwires_t x = MAX31865_2WIRE);
danjulio 0:9294dd756a0c 68
danjulio 0:9294dd756a0c 69 uint8_t readFault(void);
danjulio 0:9294dd756a0c 70 void clearFault(void);
danjulio 0:9294dd756a0c 71 uint16_t readRTD();
danjulio 0:9294dd756a0c 72
danjulio 0:9294dd756a0c 73 void setWires(max31865_numwires_t wires);
danjulio 0:9294dd756a0c 74 void autoConvert(bool b);
danjulio 0:9294dd756a0c 75 void enableBias(bool b);
danjulio 0:9294dd756a0c 76 bool isReady(uint16_t* rtdVal);
danjulio 0:9294dd756a0c 77 float temperature(float RTDnominal, float refResistor, uint16_t rtdVal = 0);
danjulio 0:9294dd756a0c 78
danjulio 0:9294dd756a0c 79 private:
danjulio 0:9294dd756a0c 80 bool debug;
danjulio 0:9294dd756a0c 81 int ssN; // Slave select for swspi
danjulio 0:9294dd756a0c 82 swspi& spi;
danjulio 0:9294dd756a0c 83 DigitalIn* rdyP; // Ready Pin
danjulio 0:9294dd756a0c 84
danjulio 0:9294dd756a0c 85 void readRegisterN(uint8_t addr, uint8_t buffer[], uint8_t n);
danjulio 0:9294dd756a0c 86
danjulio 0:9294dd756a0c 87 uint8_t readRegister8(uint8_t addr);
danjulio 0:9294dd756a0c 88 uint16_t readRegister16(uint8_t addr);
danjulio 0:9294dd756a0c 89
danjulio 0:9294dd756a0c 90 void writeRegister8(uint8_t addr, uint8_t reg);
danjulio 0:9294dd756a0c 91 };
danjulio 0:9294dd756a0c 92
danjulio 0:9294dd756a0c 93
danjulio 0:9294dd756a0c 94 #endif