MAX31865 RTD-to-Digital converter driver

Driver for the SPI RTD-to-Digital converter MAX31865. More...

Detailed Description

Driver for the SPI RTD-to-Digital converter MAX31865.

Overview

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.

Note
See the datasheet for more information.

Lookup table

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:

#include "max31865.h"
#include "max31865_lut.h"
Default lookup table.
Default configuration for the MAX31865 driver.

The lookup table in the application directory will override the default one.

Usage

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.

#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:45
#define SPI_DEV(x)
Default SPI device access macro.
Definition: spi.h:95
#define MAX31865_PARAM_SPI
Default SPI bus for the MAX31865 driver.
#define MAX31865_PARAM_CS_PIN
Default CS pin for the MAX31865 driver.

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...
 

Enumeration Type Documentation

◆ max31865_fault_t

Fault status of the MAX31865.

Enumerator
MAX31865_FAULT_NO_FAULT 

No fault.

MAX31865_FAULT_RTD_HIGH 

The RTD value is too high.

MAX31865_FAULT_RTD_LOW 

The RTD value is too small.

MAX31865_FAULT_CIRCUIT 

Open or shorted circuit.

MAX31865_FAULT_VOLTAGE 

Overvoltage or undervoltage on the FORCE or RTD pin.

Definition at line 149 of file max31865.h.

◆ 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

Enumerator
MAX31865_LUTCOL_CODE 

ADC code column index.

MAX31865_LUTCOL_TEMP 

Temperature column index (µ°C)

MAX31865_LUTCOL_A0 

a0 coefficient column index

MAX31865_LUTCOL_A1 

a1 coefficient column index

MAX31865_LUTCOL_NUMOF 

Number of columns in the lookup table.

Definition at line 112 of file max31865.h.

Function Documentation

◆ max31865_clear_fault()

void max31865_clear_fault ( const max31865_t dev,
uint8_t *  config 
)

Clear the fault flag.

Parameters
[in]devDevice descriptor of the driver
[out]configIf 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.

◆ max31865_detect_fault()

int max31865_detect_fault ( const max31865_t dev,
max31865_fault_t flt_code 
)

Run an automatic fault-detection cycle.

Parameters
[in]devDevice descriptor of the driver
[out]flt_codeFault 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.

Precondition
VBIAS must be on for at least 5 time constants.
Return values
0on success.
-EIOon error.

◆ max31865_init()

int max31865_init ( max31865_t dev,
const max31865_params_t params 
)

Initialize the given device.

Parameters
[in,out]devDevice descriptor of the driver
[in]paramsInitialization parameters
Return values
0on success
-ENXIOinvalid SPI device
-EINVALinvalid SPI CS pin/line

◆ max31865_oneshot()

void max31865_oneshot ( const max31865_t dev)

Start a one-shot conversion.

Parameters
[in]devDevice 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.

◆ max31865_raw_to_data()

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.

Parameters
[in]devDevice descriptor of the driver
[in]raw_dataRaw data from the MAX31865
[out]rtd_temperature_cdegcTemperature in centi-degrees Celsius (0.01°C)
Precondition
data must not be NULL
Return values
0on success
-EINVALon error

◆ max31865_read()

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.

Parameters
[in]devDevice descriptor of the driver
[out]rtd_temperature_cdegcTemperature in centi-degrees Celsius (0.01°C)
Precondition
dev and data must not be NULL

This function does a minimal error check. To get more details on the fault, call max31865_detect_fault().

Return values
0on success
-EIOif an error was detected by the MAX31865

◆ max31865_read_raw()

int max31865_read_raw ( const max31865_t dev,
uint16_t *  raw_data 
)

Read raw data from the MAX31865.

Parameters
[in]devDevice descriptor of the driver
[out]raw_dataValue 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.

Return values
0on success.
-EIOif an error was detected by the MAX31865. In this case, the temperature is not valid. Call max31865_detect_fault() for more details.

◆ max31865_switch_vbias()

void max31865_switch_vbias ( const max31865_t dev,
bool  enable 
)

Switch VBIAS on or off.

Parameters
[in]devDevice descriptor of the driver
[in]enableSet 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.

Variable Documentation

◆ max31865_lut

const int32_t max31865_lut[][4]
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:

  • RTD @ 0°C = 100Ω
  • RREF = 330Ω
  • Tmin = -200°C
  • Tmax = 650°C

Definition at line 46 of file max31865_lut.h.