Go Down

Topic: SD and MAX31865 Trouble (Read 586 times) previous topic - next topic

hougha

Hello, Im simply trying to get the MAX31865 RTD to digital converter to log temperature to an SD card. However, im struggling to get the SPI connections to work simultaneously. From browsing several other forum posts and other forums there seems to be a common trouble of the SD card taking the SPI line and not giving it back after its used, none of the solutions have worked for me.

So, im wondering how to fix my issue. ive got them both connected to SPI on an Arduino Mega 2560. with my MAX chipselect being 34 and the SD chip select being 38. im using the very basic SD Card holder from spark fun (no circuitry, essentially just the holder), and the sparkfun Logic Level Converter (https://www.sparkfun.com/products/12009).

Code: [Select]
/***************************************************
  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 <Adafruit_MAX31865.h>

// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 max = Adafruit_MAX31865(34, 51, 50, 52);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 max = Adafruit_MAX31865(34);

// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
#define RREF      4300.0
// The 'nominal' 0-degrees-C resistance of the sensor
// 100.0 for PT100, 1000.0 for PT1000
#define RNOMINAL  1000.0

#include <SPI.h>
#include <SdFat.h>
const int chipSelect = 38;
const int RTDcs = 34;
float x = 0.00;
SdFat SD;
File dataFile;

void setup() {

  pinMode(chipSelect, OUTPUT);
  pinMode(RTDcs, OUTPUT);
  pinMode(50, OUTPUT);
  pinMode(51, OUTPUT);
  pinMode(52, OUTPUT);
 
  Serial.begin(115200);

}


void loop() {
 
  max.begin(MAX31865_2WIRE);
  uint16_t rtd = max.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(max.temperature(RNOMINAL, RREF));
  x = max.temperature(RNOMINAL, RREF);

  Serial.println(x);


  delay(20);
 
 if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
 }

  Serial.println("SD online");
  dataFile = SD.open("datalog.txt", FILE_WRITE); 
  if (dataFile) {
      dataFile.print(x);
      dataFile.println();
      dataFile.close();
       //print to the serial port too:
      Serial.println("Recorded");
  }
   
    // if the file isn't open, pop up an error:
  else {
      Serial.println("error opening datalog.txt");
  }
  //SD.end();
  digitalWrite(chipSelect, HIGH);
  digitalWrite(RTDcs, HIGH);
  //SPI.transfer(0x80);
  //SPI.setDataMode(SPI_MODE3);
  /*
  digitalWrite(51, HIGH);
  digitalWrite(50, HIGH);
  digitalWrite(52, HIGH);
  */
  Serial.println();
  delay(1000);

}



When i run this code the RTD read correctly for the first pass of the code:

RTD value: 8300
Ratio = 0.25329589
Resistance = 1089.17236328
Temperature = 22.89
22.86
SD online
Recorded


but when it loops back through, the RTD reads out 0 for everything:

RTD value: 0
Ratio = 0.00000000
Resistance = 0.00000000
Temperature = -242.02
-242.02
SD online
Recorded

I tried using a logic analyzer to see what was going on (attached image).Tthe first pass of the code where the RTD is reading correctly is the first set of data and the other code loops are what follows.

Sorry for writing a book but i wanted to thoroughly cover what was going on.

TL;DR:  How can i get SD and MAX31865 to work correctly together over SPI simultaneously


ieee488

I'd make sure your code is working for the RTD first.

Then worry about both together.


hougha

Yes, ive gotten both working separately. On my serial monitor, the first instance of the loop prints correctly, im assuming this is because the RTD is read first then the SD card is initialized but after the SD is initialized the RTD stops working.

Go Up