Skip to content

Commit f69ca1a

Browse files
committed
Changes for multi probe (different types) and shared library for TC and RTD
1 parent 11655b6 commit f69ca1a

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

src/utility/RTD/MAX31865.cpp

+19-10
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,12 @@
33
MAX31865Class::MAX31865Class(PinName cs, SPIClass& spi) : _cs(cs), _spi(&spi), _spiSettings(1000000, MSBFIRST, SPI_MODE1) {
44
}
55

6-
bool MAX31865Class::begin(int wires) {
7-
_spi.begin();
6+
bool MAX31865Class::begin() {
87
_spi->begin();
98

109
pinMode(_cs, OUTPUT);
1110
digitalWrite(_cs, HIGH);
1211

13-
// sets 2 or 4 wire
14-
if (wires == THREE_WIRE) {
15-
writeByte(MAX31856_CONFIG_REG, (readByte(MAX31856_CONFIG_REG) | MAX31856_CONFIG_3_WIRE));
16-
} else {
17-
writeByte(MAX31856_CONFIG_REG, (readByte(MAX31856_CONFIG_REG) & MAX31856_CONFIG_WIRE_MASK));
18-
}
19-
2012
// disable bias
2113
writeByte(MAX31856_CONFIG_REG, readByte(MAX31856_CONFIG_REG) & MAX31856_CONFIG_BIAS_MASK);
2214

@@ -32,6 +24,23 @@ bool MAX31865Class::begin(int wires) {
3224
return true;
3325
}
3426

27+
bool MAX31865Class::begin(uint8_t probeType) { // Deprecate in future
28+
begin();
29+
30+
setRTDType(probeType);
31+
32+
return true;
33+
}
34+
35+
void MAX31865Class::setRTDType(uint8_t probeType) {
36+
// sets 2 or 4 wire
37+
if (probeType == PROBE_RTD_3W) {
38+
writeByte(MAX31856_CONFIG_REG, (readByte(MAX31856_CONFIG_REG) | MAX31856_CONFIG_3_WIRE));
39+
} else {
40+
writeByte(MAX31856_CONFIG_REG, (readByte(MAX31856_CONFIG_REG) & MAX31856_CONFIG_WIRE_MASK));
41+
}
42+
}
43+
3544
void MAX31865Class::clearFault(void) {
3645
writeByte(MAX31856_CONFIG_REG, (readByte(MAX31856_CONFIG_REG) & MAX31856_CONFIG_CLEAR_FAULT_CYCLE) | MAX31856_CONFIG_CLEAR_FAULT);
3746
}
@@ -82,7 +91,7 @@ bool MAX31865Class::getVoltageFault(uint8_t fault) {
8291
return false;
8392
}
8493

85-
float MAX31865Class::readTemperature(float RTDnominal, float refResistor) {
94+
float MAX31865Class::readRTDTemperature(float RTDnominal, float refResistor) {
8695
float Z1, Z2, Z3, Z4, Rt, temp;
8796

8897
Rt = readRTD();

src/utility/RTD/MAX31865.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <Arduino.h>
55
#include <mbed.h>
66
#include <SPI.h>
7+
#include "pins_mc.h"
78

89
#define MAX31856_CONFIG_REG 0x00
910
#define MAX31856_RTD_MSB_REG 0x01
@@ -47,17 +48,22 @@
4748
#define RTD_A 3.9083e-3
4849
#define RTD_B -5.775e-7
4950

50-
#define TWO_WIRE 0
51-
#define THREE_WIRE 1
51+
#define PROBE_RTD_2W 3
52+
#define PROBE_RTD_3W 4
53+
54+
#define TWO_WIRE PROBE_RTD_2W
55+
#define THREE_WIRE PROBE_RTD_3W
5256

5357
class MAX31865Class {
5458
public:
5559
MAX31865Class(PinName cs = MC_RTD_CS_PIN, SPIClass& spi = SPI);
5660

57-
bool begin(int wires);
61+
bool begin();
62+
bool begin(uint8_t probeType); //Deprecate in future
5863
void end();
5964

60-
float readTemperature(float RTDnominal, float refResistor);
65+
void setRTDType(uint8_t probeType);
66+
float readRTDTemperature(float RTDnominal, float refResistor);
6167
uint8_t readFault(void);
6268
void clearFault(void);
6369
uint32_t readRTD();

0 commit comments

Comments
 (0)