From 25d7146022d843d07c511a54489aa5f7f1245e48 Mon Sep 17 00:00:00 2001 From: Adrian Siemieniak Date: Sun, 15 Mar 2020 18:59:37 +0100 Subject: [PATCH 1/2] Added possibility to use other SPI device --- src/MAX31855.cpp | 13 +++++++------ src/MAX31855.h | 10 ++++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/MAX31855.cpp b/src/MAX31855.cpp index 97e8492..0643f4f 100644 --- a/src/MAX31855.cpp +++ b/src/MAX31855.cpp @@ -14,7 +14,7 @@ near the converter because this may produce an errors. - It is strongly recommended to add a 10nF/0.01mF ceramic surface-mount capacitor, placed across the T+ and T- pins, to filter noise on the thermocouple lines. - + written by : enjoyneering79 sourse code: https://github.com/enjoyneering/MAX31855 @@ -68,12 +68,13 @@ MAX31855::MAX31855(uint8_t cs) Initializes & configures hardware SPI */ /**************************************************************************/ -void MAX31855::begin(void) +void MAX31855::begin(SPIClass *SPI_pointer) { pinMode(_cs, OUTPUT); digitalWrite(_cs, HIGH); //disables SPI interface for MAX31855, but it will initiate measurement/conversion - SPI.begin(); //setting hardware SCK, MOSI, SS to output, pull SCK, MOSI low & SS high + MAXSPI = SPI_pointer; + MAXSPI->begin(); //setting hardware SCK, MOSI, SS to output, pull SCK, MOSI low & SS high delay(MAX31855_CONVERSION_POWER_UP_TIME); } @@ -231,18 +232,18 @@ int32_t MAX31855::readRawData(void) delay(MAX31855_CONVERSION_TIME); - SPI.beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE0)); //up to 5MHz, read MSB first, SPI mode 0, see note + MAXSPI->beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE0)); //up to 5MHz, read MSB first, SPI mode 0, see note digitalWrite(_cs, LOW); //set software CS low to enable SPI interface for MAX31855 for (uint8_t i = 0; i < 2; i++) //read 32-bits via hardware SPI, in order MSB->LSB (D31..D0 bit) { - rawData = (rawData << 16) | SPI.transfer16(0x0000); //chip has read only SPI & MOSI not connected, so it doesn't metter what to send + rawData = (rawData << 16) | MAXSPI->transfer16(0x0000); //chip has read only SPI & MOSI not connected, so it doesn't metter what to send } digitalWrite(_cs, HIGH); //disables SPI interface for MAX31855, but it will initiate measurement/conversion - SPI.endTransaction(); //de-asserting hardware CS & free hw SPI for other slaves + MAXSPI->endTransaction(); //de-asserting hardware CS & free hw SPI for other slaves return rawData; } diff --git a/src/MAX31855.h b/src/MAX31855.h index 340daaa..b7d7c80 100644 --- a/src/MAX31855.h +++ b/src/MAX31855.h @@ -14,7 +14,7 @@ near the converter because this may produce an errors. - It is strongly recommended to add a 10nF/0.01mF ceramic surface-mount capacitor, placed across the T+ and T- pins, to filter noise on the thermocouple lines. - + written by : enjoyneering79 sourse code: https://github.com/enjoyneering/MAX31855 @@ -60,9 +60,7 @@ #include //use for PROGMEM Arduino STM32 #endif -#ifndef MAX31855_SOFT_SPI //enable upload hw driver spi.h #include -#endif #define MAX31855_CONVERSION_POWER_UP_TIME 200 //in milliseconds @@ -87,15 +85,15 @@ class MAX31855 public: MAX31855(uint8_t cs); - void begin(void); + void begin(SPIClass *SPI_pointer = &SPI); uint8_t detectThermocouple(int32_t rawValue = MAX31855_FORCE_READ_DATA); uint16_t getChipID(int32_t rawValue = MAX31855_FORCE_READ_DATA); float getTemperature(int32_t rawValue = MAX31855_FORCE_READ_DATA); float getColdJunctionTemperature(int32_t rawValue = MAX31855_FORCE_READ_DATA); virtual int32_t readRawData(void); - - private: + private: + SPIClass * MAXSPI = NULL; protected: uint8_t _cs; }; From acba88544aa067bc37f087aa64d37062b996114a Mon Sep 17 00:00:00 2001 From: Adrian Siemieniak Date: Sun, 22 Mar 2020 17:37:40 +0100 Subject: [PATCH 2/2] Lowered the clock value /10 --- src/MAX31855.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MAX31855.cpp b/src/MAX31855.cpp index 0643f4f..2569b92 100644 --- a/src/MAX31855.cpp +++ b/src/MAX31855.cpp @@ -232,7 +232,7 @@ int32_t MAX31855::readRawData(void) delay(MAX31855_CONVERSION_TIME); - MAXSPI->beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE0)); //up to 5MHz, read MSB first, SPI mode 0, see note + MAXSPI->beginTransaction(SPISettings(500000, MSBFIRST, SPI_MODE0)); //up to 5MHz, read MSB first, SPI mode 0, see note digitalWrite(_cs, LOW); //set software CS low to enable SPI interface for MAX31855