Skyward boardcore
Loading...
Searching...
No Matches
MAX31856.h
Go to the documentation of this file.
1/* Copyright (c) 2023 Skyward Experimental Rocketry
2 * Author: Alberto Nidasio
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
27#include <sensors/Sensor.h>
28
29#include "MAX31856Data.h"
30
31namespace Boardcore
32{
33
47class MAX31856 : public Sensor<MAX31856Data>
48{
49public:
50 enum class ThermocoupleType : uint8_t
51 {
52 B_TYPE = 0x0,
53 E_TYPE = 0x1,
54 J_TYPE = 0x2,
55 K_TYPE = 0x3,
56 N_TYPE = 0x4,
57 R_TYPE = 0x5,
58 S_TYPE = 0x6,
59 T_TYPE = 0x7,
60 GAIN_8 = 0x8,
61 GAIN_32 = 0x9,
62 };
63
64 MAX31856(SPIBusInterface& bus, miosix::GpioPin cs,
67
69
70 bool init();
71
72 bool selfTest();
73
79 bool checkConnected();
80
82
83 void setColdJunctionOffset(float offset);
84
85protected:
86 MAX31856Data sampleImpl() override;
87
88private:
89 SPISlave slave;
91
92 PrintLogger logger = Logging::getLogger("max31856");
93
94 enum Registers : uint8_t
95 {
96 CR0 = 0x0,
97 CR1 = 0x1,
98 MASK = 0x2,
99 CJHF = 0x3,
100 CJLF = 0x4,
101 LTHFTH = 0x5,
102 LTHFTL = 0x6,
103 LTLFTH = 0x7,
104 LTLFTL = 0x8,
105 CJTO = 0x9,
106 CJTH = 0xa,
107 CJTL = 0xb,
108 LTCBH = 0xc,
109 LTCBM = 0xd,
110 LTCBL = 0xe,
111 SR = 0xf,
112 };
113
114 static constexpr uint8_t CR0_CMODE = 0x1 << 7;
115 static constexpr uint8_t CR0_OCFAULT_0 = 0x1 << 4;
116 static constexpr uint8_t SR_OPEN = 0x1 << 0;
117
118 static constexpr float TC_TEMP_LSB_VALUE = 0.007812; // [°C]
119 static constexpr float CJ_TEMP_LSB_VALUE = 0.0625; // [°C]
120};
121
122} // namespace Boardcore
static PrintLogger getLogger(const string &name)
MAX31855 thermocouple sensor driver.
Definition MAX31856.h:48
MAX31856Data sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
Definition MAX31856.cpp:98
bool checkConnected()
Checks whether the thermocouple is connected or not.
Definition MAX31856.cpp:65
bool selfTest()
Check if the sensor is working.
Definition MAX31856.cpp:63
bool init()
Initialize the sensor.
Definition MAX31856.cpp:45
static SPIBusConfig getDefaultSPIConfig()
Definition MAX31856.cpp:36
void setColdJunctionOffset(float offset)
Definition MAX31856.cpp:91
void setThermocoupleType(ThermocoupleType type)
Definition MAX31856.cpp:85
MAX31856(SPIBusInterface &bus, miosix::GpioPin cs, SPIBusConfig config=getDefaultSPIConfig(), ThermocoupleType type=ThermocoupleType::K_TYPE)
Definition MAX31856.cpp:30
Interface for low level access of a SPI bus as a master.
Base sensor class with has to be extended by any sensor driver.
Definition Sensor.h:91
This file includes all the types the logdecoder script will decode.
SPI Bus configuration for a specific slave.
Contains information about a single SPI slave device.