Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to use other SPI device #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/MAX31855.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(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

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;
}
10 changes: 4 additions & 6 deletions src/MAX31855.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -60,9 +60,7 @@
#include <avr/pgmspace.h> //use for PROGMEM Arduino STM32
#endif

#ifndef MAX31855_SOFT_SPI //enable upload hw driver spi.h
#include <SPI.h>
#endif


#define MAX31855_CONVERSION_POWER_UP_TIME 200 //in milliseconds
Expand All @@ -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;
};
Expand Down