difference between teensy3.6 and Teensy4.1 SPI configuration

Status
Not open for further replies.

Bastiaan

Well-known member
Hi group,

good morning,

I solved the part that the tft screen is working again. now to the real problem.

i cant get the code working on a teensy4.1, it worked before on a teensy3.6, its probably a simple question.
why is the Thermocouple not recognized. it doesnt show an error. also not over the Serial monitor. it just outputs 0 degrees and 0 Raw value.

  1. what i did:
    I copied the exact same components from the Evaluation board for the max31855 https://datasheets.maximintegrated.com/en/ds/MAX31855EVKIT.pdf page 6 i added the inductors and the nup2105 in between. no results.
    i removed the nup2105 and left the inductors where they are.
    I am getting a reading on my serial monitor, however this also occurs before, during and after cutting the wires. serialmonitor output.PNG

Question:where do I place the SPI1.begin(); and where to SPI1.setSCK(27) and SPI1.setMISO(39)?;
also probing with the scope gets me Zero signals on the display

Code:
**************************************************/

#include <SPI.h>
#include "Adafruit_MAX31855.h"

// Default connection is using software SPI, but comment and uncomment one of
// the two examples below to switch between software SPI and hardware SPI:

// Example creating a thermocouple instance with software SPI on any three
// digital IO pins.

#define MAXDO   39
#define MAXCS   36
#define MAXCLK  27

// initialize the Thermocouple
Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);

// Example creating a thermocouple instance with hardware SPI
// on a given CS pin.
//#define MAXCS   10
//Adafruit_MAX31855 thermocouple(MAXCS);

void setup() {
  Serial.begin(9600);

  while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc

  Serial.println("MAX31855 test");
  // wait for MAX chip to stabilize
  delay(500);
  Serial.print("Initializing sensor...");
  if (!thermocouple.begin()) {
    Serial.println("ERROR.");
    while (1) delay(10);
  }
  Serial.println("DONE.");
}

void loop() {
  // basic readout test, just print the current temp
   Serial.print("Internal Temp = ");
   Serial.println(thermocouple.readInternal());

   double c = thermocouple.readCelsius();
   if (isnan(c)) {
     Serial.println("Something wrong with thermocouple!");
   } else {
     Serial.print("C = ");
     Serial.println(c);
   }
   //Serial.print("F = ");
   //Serial.println(thermocouple.readFahrenheit());

   delay(1000);
}
 
i also added into the void Setup the:
Code:
  SPI.begin();
  SPI1.setSCK(27);
  SPI1.setMISO(39);
  SPI1.begin();

do I also have to set something like the CS to SPI1.setCS(36)?

i am now getting pulses on the SCK2 (pin 27) that look like a train of pulses i added a 100ohm resistor in series with the sck pin

but i am not getting output pulses from the max31855 at all.
 
Sorry, I don't know this library at all,

But my quick look at it up on github: https://github.com/adafruit/Adafruit-MAX31855-library/blob/master/Adafruit_MAX31855.cpp#L53
And I don't see any of their constructors allowing you to pass through which SPIDevice to use, which most of their libraries do support.
Nor do they allow it on the begin method. Most of their classes allow it one of those two ways.

You probably should be able to do it pretty easy: Example with Constructor, maybe something like:
Code:
class Adafruit_MAX31855 {
public:
  Adafruit_MAX31855(int8_t _sclk, int8_t _cs, int8_t _miso);
  Adafruit_MAX31855(int8_t _cs[COLOR="#FF0000"], SPIClass *theSPI = &SPI[/COLOR]);

And the implementation something like:
Code:
Adafruit_MAX31855::Adafruit_MAX31855(int8_t _cs[COLOR="#FF0000"], SPIClass *theSP[/COLOR]I) : spi_dev(_cs, 1000000[COLOR="#FF0000"], SPI_BITORDER_MSBFIRST, SPI_MODE0, theSPI[/COLOR]) {}

Again I have not tried this. Could be it's own constructor, could do something similar for the full parameter version...

But you may want to raise an issue with Adafruit library on this and/or create a Pull Request back to them. There may be some issues with some devices not supporting SPIClass and may need to be #ifdef ...
 
thanks for the fast reply Kurt!
i dont have a clue what the SPIClass *theSPI = &SPI means and the implementation
Adafruit_MAX31855::Adafruit_MAX31855(int8_t _cs, SPIClass *theSPI)
: spi_dev(_cs, 1000000, SPI_BITORDER_MSBFIRST, SPI_MODE0, theSPI) {}

i had this code running on the teensy3.6. but somehow the chip doesnt react back to the teensy, something is a miss.

i didnt add the settings for the SPI ill check that tonight.

best regards

Bastiaan
 
so i changed the max31855 cpp and h file, as suggested on github. still getting zero values, and no errors.
i tried adding the spi.begin(); but that didnt do anything as well.

i restarted the arduino and the teensyarduino bootloader just in case.

ill try soldering tomrrow another max31855 in place.

Code:
/***************************************************


#include <SPI.h>
#include "Adafruit_MAX31855.h"


#define MAXDO        39  
#define MAXCLK       27
#define MAX31855_2 36




SPISettings settingsTFT(25000000, MSBFIRST, SPI_MODE3);
SPISettings SettingsThermocouple(1000000, MSBFIRST, SPI_MODE1);

// initialize the Thermocouple
Adafruit_MAX31855 thermocouple(MAXCLK, MAX31855_2, MAXDO);

void setup() 
{

SPI1.setSCK(27);
SPI1.setMISO(39);

delay(100);
pinMode(36,OUTPUT);
digitalWrite(MAX31855_2,HIGH);
  SPI1.begin();



  
  Serial.begin(9600);

  while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc

  Serial.println("MAX31855 test");
  // wait for MAX chip to stabilize
  delay(500);
  Serial.print("Initializing sensor...");
  if (!thermocouple.begin()) {
    Serial.println("ERROR.");
    while (1) delay(10);
  }
  Serial.println("DONE.");
}

void loop() {
  // basic readout test, just print the current temp
   Serial.print("Internal Temp = ");
   Serial.println(thermocouple.readInternal());

   double c = thermocouple.readCelsius();
   if (isnan(c)) {
     Serial.println("Something wrong with thermocouple!");
   } else {
     Serial.print("C = ");
     Serial.println(c);
   }
   //Serial.print("F = ");
   //Serial.println(thermocouple.readFahrenheit());

   delay(1000);
}
}


serial monitor max31855.png
 
Last edited:
You might simply try:

Adafruit_MAX31855 thermocouple(MAX_CS_PIN,&SPI1);
Whatever your CS pin is...
And I will assume that it will take care of speeds and the like of SPI...
You will probably need as pin 1 is the default one: SPI1.setMISO(39);
You probably don't need the setSCK as pin 27 is the default (and only)...
 
I just encountered the same issues with my latest project. I was unable to get any temperature data from my MAX31855 using a Teensy 4.1.
With this thread I got the board to work. I am new at this so it took me a while to piece together the provide source code and the suggested changes that got it to work.

This thread has been very helpful to me. Thank you.

For clarity, here is the full source code I got to work. It incorporates the suggestions made above with the original source code from Adafruit.

Code:
/***************************************************
  This is an example for the Adafruit Thermocouple Sensor w/MAX31855K

  Designed specifically to work with the Adafruit Thermocouple Sensor
  ----> https://www.adafruit.com/products/269

  These displays use SPI to communicate, 3 pins are required to
  interface
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <SPI.h>
#include "Adafruit_MAX31855.h"

// Setup Pins Used For SPI
#define SPI1_MISO  39
#define SPI1_SCK   27

// Setup chip select pin for the MAX31855 breakout board
#define THERMO_1   36

// Example creating a thermocouple instance with hardware SPI
// on SPI1 using specified CS pin.
Adafruit_MAX31855 thermocouple(THERMO_1, &SPI1);

void setup() {
  Serial.begin(9600);

  while (!Serial) delay(1); // wait for Serial

  // Setup the SPI pins
  SPI1.setMISO(SPI1_MISO);  // Call to set MSIO pin is necessary.
  // SPI1.setSCK(SPI1_SCK); // Call to set SCK pin is not necessary.
  // SPI1.begin();          // Call to begin() is not necessary.

  Serial.println("MAX31855 on Teensy 4.1");

  // wait for MAX chip to stabilize
  delay(500);

  Serial.print("Initializing sensor...");

  if (!thermocouple.begin()) {
    Serial.println("ERROR."); 
    while (1) delay(10);
  }

  Serial.println("DONE.");
}

void loop() {
  // basic readout test, just print the current temp
   Serial.print("Internal Temp = ");
   Serial.println(thermocouple.readInternal());

   double c = thermocouple.readCelsius();
   if (isnan(c)) {
     Serial.println("Something wrong with thermocouple!");
   } else {
     Serial.print("C = ");
     Serial.println(c);
   }
 
   delay(1000); // Delays any shorter than ~180ms causes frequent read errors
}
 
Status
Not open for further replies.
Back
Top