Cant get multiple SPI devices working at the same time (ST7735, MAX31865)

Hi,

I'm having trouble to get a ST7735 tft and MAX31865 PT100 board working at the same time with my Uno R3. I can get both of them working by themselves with the examples available. I also can get the MAX81365 to post a correct temperature once, but as soon as I initialize the ST7735 it stops working and returns a reading which is just 0, or over/undervoltage error.

What am I doing wrong?

/*************************************************** 
  This is a library for the Adafruit PT100/P1000 RTD Sensor w/MAX31865

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

  This sensor uses SPI to communicate, 4 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 <Arduino.h>
#include <Adafruit_MAX31865.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for 
#define TFT_CS        10
#define TFT_RST        4 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC         7

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 thermo = Adafruit_MAX31865(2, 11, 12, 13);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 thermo = Adafruit_MAX31865(10);

// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
#define RREF      430.0
// The 'nominal' 0-degrees-C resistance of the sensor
// 100.0 for PT100, 1000.0 for PT1000
#define RNOMINAL  100.0
uint8_t count = 0;
void setup() {
  Serial.begin(115200);
  Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
  pinMode (2, OUTPUT);
  pinMode (10, OUTPUT);
  //SPI.begin();
  uint16_t time = millis();
  time = millis() - time;
  thermo.begin(MAX31865_3WIRE);  // set to 2WIRE or 4WIRE as necessary
  //digitalWrite(10, HIGH);
  //digitalWrite(2, HIGH);
  } 


void loop() {
  count += 1;
  Serial.print(count);
  //SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0));
  digitalWrite(2, LOW);
  uint16_t rtd = thermo.readRTD();
  Serial.print("RTD value: "); Serial.println(rtd);
  float ratio = rtd;
  ratio /= 32768;
  Serial.print("Ratio = "); Serial.println(ratio,8);
  Serial.print("Resistance = "); Serial.println(RREF*ratio,8);
  Serial.print("Temperature = "); Serial.println(thermo.temperature(RNOMINAL, RREF));
  float temptest = thermo.temperature(RNOMINAL, RREF);
  // Check and print any faults
  uint8_t fault = thermo.readFault();
  if (fault) {
    Serial.print("Fault 0x"); Serial.println(fault, HEX);
    if (fault & MAX31865_FAULT_HIGHTHRESH) {
      Serial.println("RTD High Threshold"); 
    }
    if (fault & MAX31865_FAULT_LOWTHRESH) {
      Serial.println("RTD Low Threshold"); 
    }
    if (fault & MAX31865_FAULT_REFINLOW) {
      Serial.println("REFIN- > 0.85 x Bias"); 
    }
    if (fault & MAX31865_FAULT_REFINHIGH) {
      Serial.println("REFIN- < 0.85 x Bias - FORCE- open"); 
    }
    if (fault & MAX31865_FAULT_RTDINLOW) {
      Serial.println("RTDIN- < 0.85 x Bias - FORCE- open"); 
    }
    if (fault & MAX31865_FAULT_OVUV) {
      Serial.println("Under/Over voltage"); 
    }
    thermo.clearFault();
    
  }
  Serial.println();
  digitalWrite(2, HIGH);
  //SPI.endTransaction();
  digitalWrite(10, LOW);
  tft.initR(INITR_BLACKTAB);
  tft.fillScreen(ST77XX_BLACK);
  testdrawtext(count,ST77XX_RED,3);
  digitalWrite(10, HIGH);
  //SPI.endTransaction();
  //SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE1));

  delay(1000);
}
void testdrawtext(uint8_t count, uint16_t color, uint16_t size) {
  tft.setRotation(3); // rotate 90 degrees
  tft.setTextSize(size);
  tft.setCursor(0, 0);
  tft.setTextColor(color);
  tft.setTextWrap(true);
  tft.print(count);
  }

You trying to use software SPI, try the hardware SPI option instead.

It worked! Thank you, such an easy problem. Now I only have one weird behaviour. Every loop the screen flickers white before turning black again, do you know what can cause it?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.