mirror of
https://github.com/arendst/Tasmota.git
synced 2025-04-24 14:57:16 +00:00
Change MAX31865 driver to support up to 6 thermocouples
Change MAX31865 driver to support up to 6 thermocouples selected by ``MX31865 CS`` instead of ``SSPI CS`` (#9103)
This commit is contained in:
parent
8b21d11e5b
commit
6585fc07e8
@ -64,3 +64,5 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota
|
|||||||
- Remove auto config update for all Friendlynames and Switchtopic from versions before 8.x
|
- Remove auto config update for all Friendlynames and Switchtopic from versions before 8.x
|
||||||
- Change redesigning ESP8266 GPIO internal representation in line with ESP32
|
- Change redesigning ESP8266 GPIO internal representation in line with ESP32
|
||||||
- Change new IR Raw compact format (#9444)
|
- Change new IR Raw compact format (#9444)
|
||||||
|
- Change MAX31865 driver to support up to 6 thermocouples selected by ``MX31865 CS`` instead of ``SSPI CS`` (#9103)
|
||||||
|
- Add optional support for Mitsubishi Electric HVAC by David Gwynne (#9237)
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
- Remove auto config update for all Friendlynames and Switchtopic from versions before 8.x
|
- Remove auto config update for all Friendlynames and Switchtopic from versions before 8.x
|
||||||
- Change redesigning ESP8266 GPIO internal representation in line with ESP32
|
- Change redesigning ESP8266 GPIO internal representation in line with ESP32
|
||||||
- Change new IR Raw compact format (#9444)
|
- Change new IR Raw compact format (#9444)
|
||||||
|
- Change MAX31865 driver to support up to 6 thermocouples selected by ``MX31865 CS`` instead of ``SSPI CS`` (#9103)
|
||||||
- Add optional support for Mitsubishi Electric HVAC by David Gwynne (#9237)
|
- Add optional support for Mitsubishi Electric HVAC by David Gwynne (#9237)
|
||||||
|
|
||||||
### 8.5.1 20201002
|
### 8.5.1 20201002
|
||||||
|
@ -257,7 +257,7 @@ const char kSensorNames[] PROGMEM =
|
|||||||
const char kSensorNamesFixed[] PROGMEM =
|
const char kSensorNamesFixed[] PROGMEM =
|
||||||
D_SENSOR_USER;
|
D_SENSOR_USER;
|
||||||
|
|
||||||
#define MAX_MAX31865_CS 6
|
#define MAX_MAX31865S 6
|
||||||
#define MAX_WEBCAM_DATA 8
|
#define MAX_WEBCAM_DATA 8
|
||||||
#define MAX_WEBCAM_HSD 3
|
#define MAX_WEBCAM_HSD 3
|
||||||
|
|
||||||
@ -310,6 +310,9 @@ const uint16_t kGpioNiceList[] PROGMEM = {
|
|||||||
AGPIO(GPIO_BACKLIGHT), // Display backlight control
|
AGPIO(GPIO_BACKLIGHT), // Display backlight control
|
||||||
AGPIO(GPIO_OLED_RESET), // OLED Display Reset
|
AGPIO(GPIO_OLED_RESET), // OLED Display Reset
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_MAX31865
|
||||||
|
AGPIO(GPIO_SSPI_MAX31865_CS1) + MAX_MAX31865S,
|
||||||
|
#endif
|
||||||
|
|
||||||
AGPIO(GPIO_TXD), // Serial interface
|
AGPIO(GPIO_TXD), // Serial interface
|
||||||
AGPIO(GPIO_RXD), // Serial interface
|
AGPIO(GPIO_RXD), // Serial interface
|
||||||
@ -542,9 +545,6 @@ const uint16_t kGpioNiceList[] PROGMEM = {
|
|||||||
AGPIO(GPIO_MAX31855CLK), // MAX31855 Serial interface
|
AGPIO(GPIO_MAX31855CLK), // MAX31855 Serial interface
|
||||||
AGPIO(GPIO_MAX31855DO), // MAX31855 Serial interface
|
AGPIO(GPIO_MAX31855DO), // MAX31855 Serial interface
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_MAX31855
|
|
||||||
AGPIO(GPIO_SSPI_MAX31865_CS1) + MAX_MAX31865_CS,
|
|
||||||
#endif
|
|
||||||
#ifdef USE_HRE
|
#ifdef USE_HRE
|
||||||
AGPIO(GPIO_HRE_CLOCK),
|
AGPIO(GPIO_HRE_CLOCK),
|
||||||
AGPIO(GPIO_HRE_DATA),
|
AGPIO(GPIO_HRE_DATA),
|
||||||
|
@ -18,8 +18,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef USE_MAX31865
|
#ifdef USE_MAX31865
|
||||||
|
/*********************************************************************************************\
|
||||||
#include "Adafruit_MAX31865.h"
|
* MAX31865 - Thermocouple
|
||||||
|
\*********************************************************************************************/
|
||||||
|
|
||||||
#define XSNS_47 47
|
#define XSNS_47 47
|
||||||
|
|
||||||
@ -31,72 +32,89 @@
|
|||||||
#define PTD_WIRES MAX31865_2WIRE
|
#define PTD_WIRES MAX31865_2WIRE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int8_t init_status = 0;
|
#include "Adafruit_MAX31865.h"
|
||||||
|
|
||||||
Adafruit_MAX31865 max31865;
|
int8_t max31865_init_status = 0;
|
||||||
|
uint8_t max31865_pins_used = 0; //used as a bit array
|
||||||
|
|
||||||
|
Adafruit_MAX31865 max31865[MAX_MAX31865S];
|
||||||
|
|
||||||
struct MAX31865_Result_Struct {
|
struct MAX31865_Result_Struct {
|
||||||
uint8_t ErrorCode;
|
uint8_t ErrorCode;
|
||||||
uint16_t Rtd;
|
uint16_t Rtd;
|
||||||
float PtdResistance;
|
float PtdResistance;
|
||||||
float PtdTemp;
|
float PtdTemp;
|
||||||
} MAX31865_Result;
|
} MAX31865_Result[MAX_MAX31865S];
|
||||||
|
|
||||||
void MAX31865_Init(void){
|
void MAX31865_Init(void) {
|
||||||
if(init_status)
|
if (max31865_init_status) { return; }
|
||||||
return;
|
|
||||||
|
|
||||||
max31865.setPins(
|
max31865_init_status = 1;
|
||||||
Pin(GPIO_SSPI_CS),
|
for (uint32_t i = 0; i < MAX_MAX31865S; i++) {
|
||||||
Pin(GPIO_SSPI_MOSI),
|
if (PinUsed(GPIO_SSPI_MAX31865_CS1, i)) {
|
||||||
Pin(GPIO_SSPI_MISO),
|
max31865_pins_used |= 1 << i; //set lowest bit
|
||||||
Pin(GPIO_SSPI_SCLK)
|
max31865[0].setPins(
|
||||||
);
|
Pin(GPIO_SSPI_MAX31865_CS1, i),
|
||||||
|
Pin(GPIO_SSPI_MOSI),
|
||||||
|
Pin(GPIO_SSPI_MISO),
|
||||||
|
Pin(GPIO_SSPI_SCLK)
|
||||||
|
);
|
||||||
|
|
||||||
if(max31865.begin(PTD_WIRES))
|
if (!max31865[i].begin(PTD_WIRES)) {
|
||||||
init_status = 1;
|
max31865_init_status = -1;
|
||||||
else
|
}
|
||||||
init_status = -1;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MAX31865_GetResult(void)
|
* MAX31865_GetResult(void)
|
||||||
* Acquires the raw data via SPI, checks for MAX31865 errors and fills result structure
|
* Acquires the raw data via SPI, checks for MAX31865 errors and fills result structure
|
||||||
*/
|
*/
|
||||||
void MAX31865_GetResult(void){
|
void MAX31865_GetResult(void) {
|
||||||
uint16_t rtd;
|
for (uint32_t i = 0; i < MAX_MAX31865S; i++) {
|
||||||
|
if (max31865_pins_used & (1 << i)) {
|
||||||
|
uint16_t rtd;
|
||||||
|
|
||||||
rtd = max31865.readRTD();
|
rtd = max31865[i].readRTD();
|
||||||
MAX31865_Result.Rtd = rtd;
|
MAX31865_Result[i].Rtd = rtd;
|
||||||
MAX31865_Result.PtdResistance = max31865.rtd_to_resistance(rtd, MAX31865_REF_RES);
|
MAX31865_Result[i].PtdResistance = max31865[i].rtd_to_resistance(rtd, MAX31865_REF_RES);
|
||||||
MAX31865_Result.PtdTemp = max31865.rtd_to_temperature(rtd, MAX31865_PTD_RES, MAX31865_REF_RES) + MAX31865_PTD_BIAS;
|
MAX31865_Result[i].PtdTemp = max31865[i].rtd_to_temperature(rtd, MAX31865_PTD_RES, MAX31865_REF_RES) + MAX31865_PTD_BIAS;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MAX31865_Show(bool Json){
|
void MAX31865_Show(bool Json) {
|
||||||
char temperature[33];
|
uint8_t report_once = 0;
|
||||||
char resistance[33];
|
for (uint32_t i = 0; i < MAX_MAX31865S; i++) {
|
||||||
|
if (max31865_pins_used & (1 << i)) {
|
||||||
|
char temperature[33];
|
||||||
|
char resistance[33];
|
||||||
|
|
||||||
dtostrfd(MAX31865_Result.PtdResistance, Settings.flag2.temperature_resolution, resistance);
|
dtostrfd(MAX31865_Result[i].PtdResistance, Settings.flag2.temperature_resolution, resistance);
|
||||||
dtostrfd(MAX31865_Result.PtdTemp, Settings.flag2.temperature_resolution, temperature);
|
dtostrfd(MAX31865_Result[i].PtdTemp, Settings.flag2.temperature_resolution, temperature);
|
||||||
|
|
||||||
if(Json){
|
if (Json) {
|
||||||
ResponseAppend_P(PSTR(",\"MAX31865\":{\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_RESISTANCE "\":%s,\"" D_JSON_ERROR "\":%d}"), \
|
ResponseAppend_P(PSTR(",\"MAX31865%c%d\":{\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_RESISTANCE "\":%s,\"" D_JSON_ERROR "\":%d}"), \
|
||||||
temperature, resistance, MAX31865_Result.ErrorCode);
|
IndexSeparator(), i, temperature, resistance, MAX31865_Result[i].ErrorCode);
|
||||||
|
if ((0 == tele_period) && (!report_once)) {
|
||||||
#ifdef USE_DOMOTICZ
|
#ifdef USE_DOMOTICZ
|
||||||
if (0 == tele_period) {
|
|
||||||
DomoticzSensor(DZ_TEMP, temperature);
|
DomoticzSensor(DZ_TEMP, temperature);
|
||||||
}
|
|
||||||
#endif // USE_DOMOTICZ
|
#endif // USE_DOMOTICZ
|
||||||
#ifdef USE_KNX
|
#ifdef USE_KNX
|
||||||
if (0 == tele_period) {
|
KnxSensor(KNX_TEMPERATURE, MAX31865_Result[i].PtdTemp);
|
||||||
KnxSensor(KNX_TEMPERATURE, MAX31865_Result.PtdTemp);
|
|
||||||
}
|
|
||||||
#endif // USE_KNX
|
#endif // USE_KNX
|
||||||
} else {
|
report_once++;
|
||||||
|
}
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
WSContentSend_PD(HTTP_SNS_TEMP, "MAX31865", temperature, TempUnit());
|
} else {
|
||||||
|
char sensorname[33];
|
||||||
|
sprintf(sensorname, "MAX31865%c%d", IndexSeparator(), i);
|
||||||
|
WSContentSend_PD(HTTP_SNS_TEMP, sensorname, temperature, TempUnit());
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
@ -106,8 +124,10 @@ void MAX31865_Show(bool Json){
|
|||||||
bool Xsns47(uint8_t function)
|
bool Xsns47(uint8_t function)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
if (PinUsed(GPIO_SSPI_MISO) && PinUsed(GPIO_SSPI_MOSI) &&
|
|
||||||
PinUsed(GPIO_SSPI_SCLK) && PinUsed(GPIO_SSPI_CS)) {
|
if (PinUsed(GPIO_SSPI_MISO) && PinUsed(GPIO_SSPI_MOSI) && PinUsed(GPIO_SSPI_SCLK) &&
|
||||||
|
(PinUsed(GPIO_SSPI_MAX31865_CS1) || PinUsed(GPIO_SSPI_MAX31865_CS1, 1) || PinUsed(GPIO_SSPI_MAX31865_CS1, 2) ||
|
||||||
|
PinUsed(GPIO_SSPI_MAX31865_CS1, 3) || PinUsed(GPIO_SSPI_MAX31865_CS1, 4) || PinUsed(GPIO_SSPI_MAX31865_CS1, 5))) {
|
||||||
|
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case FUNC_INIT:
|
case FUNC_INIT:
|
||||||
@ -119,12 +139,12 @@ bool Xsns47(uint8_t function)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case FUNC_JSON_APPEND:
|
case FUNC_JSON_APPEND:
|
||||||
MAX31865_Show(true);
|
MAX31865_Show(1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
case FUNC_WEB_SENSOR:
|
case FUNC_WEB_SENSOR:
|
||||||
MAX31865_Show(false);
|
MAX31865_Show(0);
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user