Tool Libs
UMIT-TIROL Institute of Automation and Control Engineering library collection
 
Loading...
Searching...
No Matches
MAX31855.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <cmath>
8#include <cstdint>
9
10#include "sys/spi.h"
11
20 : SPI::Device(bus, cs, {SPI::Mode::M0, SPI::FirstBit::MSB}) { }
21
27 double temp() {
28 if (data.FAULT) return NAN;
29 return data.TEMP * 0.25;
30 }
31
37 double internal() {
38 if (data.FAULT) return NAN;
39 return data.INTERNAL * 0.0625;
40 }
41
45 void sense() {
46 bus.trypush({
47 .dev = this,
48 .data = 4,
49 .dir = SPI::Request::MISO,
50 });
51 }
52
53 void callback(const SPI::Request rq) override {
54 int32_t raw = rq.data.buf[0]<<24 | rq.data.buf[1]<<16 | rq.data.buf[2]<<8 | rq.data.buf[3];
55 data = *(sensor *)&raw;
56 }
57
58 struct sensor {
59 uint8_t OC:1;
60 uint8_t SCG:1;
61 uint8_t SCV:1;
62 uint8_t :1;
63 int16_t INTERNAL:12;
64 uint8_t FAULT:1;
65 uint8_t :1;
66 int16_t TEMP:14;
67 } data = {};
68};
Wrapper class for simple digital input/output pin.
Definition gpio.h:13
Copyright (c) 2023 IACE.
Implementation of MAX31855 thermocouple temperature measurement.
Definition MAX31855.h:13
double temp()
measured sensor temperature
Definition MAX31855.h:27
double internal()
measured internal chip temperature
Definition MAX31855.h:37
struct MAX31855::sensor data
sensor data struct. lsb to msb order.
void callback(const SPI::Request rq) override
is called as soon as requested data arrived over wire
Definition MAX31855.h:53
MAX31855(Sink< SPI::Request > &bus, DIO cs)
Constructor.
Definition MAX31855.h:19
void sense()
request measurement of sensor data
Definition MAX31855.h:45
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
@ MISO
Master in, Slave out.
Definition spi.h:59
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