38 REG_HIGH_FAULT_THRESHOLD = 3,
39 REG_LOW_FAULT_THRESHOLD = 5,
70 : SPI::Device(bus,
cs, {SPI::Mode::M3, SPI::FirstBit::MSB}), Rnom(c.Rnom), Rref(c.Rref) {
133 const uint8_t *raw = rq.
data.buf;
139 data.rtd = raw[2] << 8 | raw[3];
140 data.threshold.high = raw[4]<<8 | raw[5];
141 data.threshold.low = raw[6]<<8 | raw[7];
145 data.rtd = raw[1] << 8 | raw[2];
161 data.rtd = data.rtd >> 1 << 1;
163 setConfig(data.config | 1 << 1);
174 .data = {WRITE | REG_LOW_FAULT_THRESHOLD, (uint8_t)(thr>>8), (uint8_t)thr},
186 .data = {WRITE | REG_HIGH_FAULT_THRESHOLD, (uint8_t)(thr>>8), (uint8_t)thr},
192 const double Rnom = 1000;
193 const double Rref = 0;
195 const double alpha = 0.00385055;
196 const double a = 3.9083e-3;
197 const double b = -5.775e-7;
198 const double a2b = a/(2*b);
214 void setConfig(uint8_t val) {
218 .data = {WRITE|REG_CONFIG, data.config},
226 .data = {READ|REG_RTD, 0, 0},
231 void getStatusData() {
234 .data = {READ|REG_STATUS, 0},
242 .data = {READ|REG_CONFIG, 0,0,0,0,0,0,0,0},
248 double Rrtd = (double) (data.rtd >> 1) / (1 << 15) * Rref;
250 return (Rrtd - Rnom)/(Rnom * alpha);
254 double Rrtd = (double) (data.rtd >> 1) / (1 << 15) * Rref;
259 double dTemp = -a2b - sqrt(a2b*a2b - (Rnom - Rrtd)/(b*Rnom));
Wrapper class for simple digital input/output pin.
Definition gpio.h:13
size_t len
number of items stored in buffer
Definition buffer.h:21
Implementation of MAX31865 based temperature sensor.
Definition MAX31865.h:26
void sense()
async read temperature data from sensor
Definition MAX31865.h:110
double temp()
quadratic temperature approximation
Definition MAX31865.h:99
void callback(const SPI::Request rq) override
is called as soon as requested data arrived over wire
Definition MAX31865.h:131
MAX31865(Sink< SPI::Request > &bus, DIO cs, Config c={ .wires=PT2WIRE,.Rnom=100,.Rref=430, })
configure temperature sensor
Definition MAX31865.h:63
void clearFaults()
clear faults on sensor
Definition MAX31865.h:160
Type wires
number of wires
Definition MAX31865.h:50
double tempLin()
linear temperature approximation
Definition MAX31865.h:86
void readFault()
async read fault data from sensor
Definition MAX31865.h:117
void readAllData()
async read all data from sensor
Definition MAX31865.h:124
double Rref
reference resistor
Definition MAX31865.h:52
Type
Sensor Type.
Definition MAX31865.h:28
@ PT2WIRE
2 wire
Definition MAX31865.h:29
@ PT4WIRE
4 wire
Definition MAX31865.h:31
@ PT3WIRE
3 wire
Definition MAX31865.h:30
void setHThr(uint16_t thr)
set high fault threshold value
Definition MAX31865.h:183
void setLThr(uint16_t thr)
set low fault threshold value
Definition MAX31865.h:171
double Rnom
nominal resistance
Definition MAX31865.h:51
uint8_t fault()
Definition MAX31865.h:153
Sensor configuration.
Definition MAX31865.h:49
generic SPI device wrapper.
Definition spi.h:22
DIO cs
GPIO chipselect line.
Definition spi.h:25
struct defining an SPI request.
Definition spi.h:54
Buffer< uint8_t > data
transfer data
Definition spi.h:56
enum SPI::Request::Direction dir
direction the data should travel
@ MOSI
Master out, Slave in.
Definition spi.h:58
@ BOTH
Both in, Both out.
Definition spi.h:60
generic object sink, i.e.
Definition streams.h:15
void trypush(T &&t)
use this if you don't care if it's going to be successful. data gets discarded if sink is full.
Definition streams.h:28