Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 11 of 11

Thread: difference between teensy3.6 and Teensy4.1 SPI configuration

  1. #1
    Senior Member
    Join Date
    Sep 2016
    Posts
    174

    difference between teensy3.6 and Teensy4.1 SPI configuration

    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.c...31855EVKIT.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.Click image for larger version. 

Name:	serialmonitor output.PNG 
Views:	44 
Size:	10.3 KB 
ID:	24070


    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);
    }

  2. #2
    Senior Member
    Join Date
    Sep 2016
    Posts
    174
    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.

  3. #3
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    11,653
    Sorry, I don't know this library at all,

    But my quick look at it up on github: https://github.com/adafruit/Adafruit...X31855.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, SPIClass *theSPI = &SPI);
    And the implementation something like:
    Code:
    Adafruit_MAX31855::Adafruit_MAX31855(int8_t _cs, SPIClass *theSPI) : spi_dev(_cs, 1000000, SPI_BITORDER_MSBFIRST, SPI_MODE0, theSPI) {}
    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 ...

  4. #4
    Senior Member
    Join Date
    Sep 2016
    Posts
    174
    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

  5. #5
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    11,653
    I went ahead and created an issue up on their library: https://github.com/adafruit/Adafruit...rary/issues/43

  6. #6
    Senior Member
    Join Date
    Sep 2016
    Posts
    174
    Darn your faster, I was almost ready typing to their support.

  7. #7
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    11,653
    You might try the branch that I have an open Pull Request on: https://github.com/KurtE/Adafruit-MA...cify_which_spi

    As soon as I opened the issue, LadyAda goes that would be good, please do a PR.... So it would be good to verify that it solves the issue.

  8. #8
    Senior Member
    Join Date
    Sep 2016
    Posts
    174
    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);
    }
    }

    Click image for larger version. 

Name:	serial monitor max31855.png 
Views:	43 
Size:	5.1 KB 
ID:	24077
    Last edited by Bastiaan; 03-15-2021 at 08:42 PM.

  9. #9
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    11,653
    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)...

  10. #10
    Senior Member
    Join Date
    Sep 2016
    Posts
    174
    it works thanks a million!

  11. #11
    Junior Member
    Join Date
    Oct 2021
    Posts
    1
    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
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •