Driver for the SPI RTD-to-Digital converter MAX31865. More...
Driver for the SPI RTD-to-Digital converter MAX31865.
The MAX31865 is a resistance-to-digital converter optimized for platinum resistance temperature detectors (RTDs). An external resistor sets the sensitivity for the RTD being used and a precision delta-sigma ADC converts the ratio of the RTD resistance to the reference resistance on the board, to a 15-bit word.
The RTD register and the threshold registers represent the ratio of the RTD resistance to the reference resistance.
In order to convert the ADC code to temperature with a decent precision and low CPU usage by using fixed point computation, this driver uses a lookup table. The values of the lookup table depend on the type of RTD, the reference resistance on the board and the temperature range. A default lookup table for a Pt100 sensor, a reference resistance of 330Ω and a temperature range of -200..+650°C is provided. With this lookup table, the standard deviation of the computation error over the -200..+650°C range is 0.011°C and the maximum error is 0.039°C.
If the default lookup doesn't fit the application, the user can generate a custom one with the Python script drivers/max31865/dist/genlut.py
. Type genlut.py -h
for help. Move the generated header file to the application project directory. In the application code, include max31865_lut.h
. The header files must be included in the following order:
The lookup table in the application directory will override the default one.
The default configuration is set in max31865_params.h as a max31865_params_t structure. Most of them can be changed using the preprocessor definitions either in the board definition in board.h
or in the Makefile of the application using the CFLAGS
variable. In particular, let the SPI device and chip select pin fit the board.
The easiest way to read the temperature is to call max31865_read(). In critical applications, where a sensor failure may cause damage to the system, calling max31865_read_raw(), max31865_raw_to_data() and max31865_detect_fault() independently provides a better control on fault detection.
Modules | |
MAX31865 constants | |
Files | |
file | max31865.h |
file | max31865_lut.h |
Default lookup table. | |
file | max31865_params.h |
Default configuration for the MAX31865 driver. | |
Data Structures | |
struct | max31865_params_t |
Device initialization parameters. More... | |
struct | max31865_t |
Device descriptor for the driver. More... | |
Enumerations | |
enum | max31865_lutcols_t { MAX31865_LUTCOL_CODE = 0 , MAX31865_LUTCOL_TEMP = 1 , MAX31865_LUTCOL_A0 = 2 , MAX31865_LUTCOL_A1 = 3 , MAX31865_LUTCOL_NUMOF } |
Lookup table column indexes. More... | |
enum | max31865_fault_t { MAX31865_FAULT_NO_FAULT = 0 , MAX31865_FAULT_RTD_HIGH = 1 , MAX31865_FAULT_RTD_LOW = 2 , MAX31865_FAULT_CIRCUIT = 3 , MAX31865_FAULT_VOLTAGE = 4 } |
Fault status of the MAX31865. More... | |
Functions | |
int | max31865_init (max31865_t *dev, const max31865_params_t *params) |
Initialize the given device. More... | |
void | max31865_clear_fault (const max31865_t *dev, uint8_t *config) |
Clear the fault flag. More... | |
int | max31865_read (const max31865_t *dev, int32_t *rtd_temperature_cdegc) |
Read data from the MAX31865. More... | |
int | max31865_read_raw (const max31865_t *dev, uint16_t *raw_data) |
Read raw data from the MAX31865. More... | |
int | max31865_raw_to_data (const max31865_t *dev, uint16_t raw_data, int32_t *rtd_temperature_cdegc) |
Convert the raw data from the MAX31865 temperature. More... | |
int | max31865_detect_fault (const max31865_t *dev, max31865_fault_t *flt_code) |
Run an automatic fault-detection cycle. More... | |
void | max31865_switch_vbias (const max31865_t *dev, bool enable) |
Switch VBIAS on or off. More... | |
void | max31865_oneshot (const max31865_t *dev) |
Start a one-shot conversion. More... | |
static const int32_t | max31865_lut [][4] |
Default lookup table for temperature conversion. More... | |
enum max31865_fault_t |
Fault status of the MAX31865.
Definition at line 149 of file max31865.h.
enum max31865_lutcols_t |
Lookup table column indexes.
The lookup table is a 2D array. This enum defines the indexes of the columns of the table. The conversion from ADC code to temperature is done with a linear interpolation between two lines of the table. The coefficients at line n are valid for the temperature range between line n and line n+1.
T = a0 + a1 × code
Definition at line 112 of file max31865.h.
void max31865_clear_fault | ( | const max31865_t * | dev, |
uint8_t * | config | ||
) |
Clear the fault flag.
[in] | dev | Device descriptor of the driver |
[out] | config | If not NULL, set to the value of the config register |
Call this function if after max31865_read() or max31865_detect_fault() if either of them reports a fault.
int max31865_detect_fault | ( | const max31865_t * | dev, |
max31865_fault_t * | flt_code | ||
) |
Run an automatic fault-detection cycle.
[in] | dev | Device descriptor of the driver |
[out] | flt_code | Fault code |
Run a full fault-detection cycle, in automatic mode. The automatic mode implies that the input filter of the ADC has a time constant smaller than 100µs. This is the case if the capacitor across the RTD has the value which is recommended in the datasheet.
The execution time of this function is at least 100µs, until the fault-detection cycle completes. It polls the configuration register to check the completion of the cycle.
0 | on success. |
-EIO | on error. |
int max31865_init | ( | max31865_t * | dev, |
const max31865_params_t * | params | ||
) |
Initialize the given device.
[in,out] | dev | Device descriptor of the driver |
[in] | params | Initialization parameters |
0 | on success |
-ENXIO | invalid SPI device |
-EINVAL | invalid SPI CS pin/line |
void max31865_oneshot | ( | const max31865_t * | dev | ) |
Start a one-shot conversion.
[in] | dev | Device descriptor of the driver |
The user must wait at least 52ms in 60Hz or 62.5ms in 50Hz filter mode for the conversion to complete, before reading the conversion result.
int max31865_raw_to_data | ( | const max31865_t * | dev, |
uint16_t | raw_data, | ||
int32_t * | rtd_temperature_cdegc | ||
) |
Convert the raw data from the MAX31865 temperature.
[in] | dev | Device descriptor of the driver |
[in] | raw_data | Raw data from the MAX31865 |
[out] | rtd_temperature_cdegc | Temperature in centi-degrees Celsius (0.01°C) |
data
must not be NULL0 | on success |
-EINVAL | on error |
int max31865_read | ( | const max31865_t * | dev, |
int32_t * | rtd_temperature_cdegc | ||
) |
Read data from the MAX31865.
This is a shortcut to read raw data and parse it to the data structure.
[in] | dev | Device descriptor of the driver |
[out] | rtd_temperature_cdegc | Temperature in centi-degrees Celsius (0.01°C) |
This function does a minimal error check. To get more details on the fault, call max31865_detect_fault().
0 | on success |
-EIO | if an error was detected by the MAX31865 |
int max31865_read_raw | ( | const max31865_t * | dev, |
uint16_t * | raw_data | ||
) |
Read raw data from the MAX31865.
[in] | dev | Device descriptor of the driver |
[out] | raw_data | Value of the RTD registers |
raw_data is a left-justified 15-bit word, representing the ratio of the RTD resistance to the reference resistance. Bit 0 is a status bit.
0 | on success. |
-EIO | if an error was detected by the MAX31865. In this case, the temperature is not valid. Call max31865_detect_fault() for more details. |
void max31865_switch_vbias | ( | const max31865_t * | dev, |
bool | enable | ||
) |
Switch VBIAS on or off.
[in] | dev | Device descriptor of the driver |
[in] | enable | Set to true to switch on, or to false to switch off VBIAS. |
The bias current of the RTD can be switched off to save power. After switching it on, wait for at least 10 time constants – 10 × 100µs, if the capacitance across the RTD is as recommended in the datasheet – before measuring a valid temperature.
|
static |
Default lookup table for temperature conversion.
The columns of this table should be indexed by max31865_lutcols_t.
This lookup table was generated by genlut.py
, provided with the max31865 driver.
Lookup table parameters:
Definition at line 46 of file max31865_lut.h.