Problem: When I plug in more than one device on the SPI bus, the MAX gives me really bad readings (see the log file below). Everything works fine if either the SD Card or just the MAX31865 are running. I don't even have this running and ordered more MAX31865's. If I cannot get this running, I have some ADS1115 boards which I will get my 3 wire PT100's running on them. I would really prefer staying with the MAX breakouts. Any suggestions would be greatly appreciated.
Arduino Mega 2560
MicroSD: Catalex
Pullup resisters on CS lines , 10k
NOTE: Running everything as 5V NOT 3V.
Mega Pin 50 (MISO)
Mega Pin 51 (MISO)
Mega Pin 52 (CLK)
Mega Pin 53 is always set to output/HIGH. I use CS pings instead of 53.
If i run the microSD by itself, it runs great. If I run the MAX31865 PT100 by itself it is fine. As soon as I put them together the MAX does not work. The microSD card works like a champ.
Wiring is simple.
Both CLK lines are in the breadboard and go to mega 52 pin.
MOSI (Master Output Slave Input) and SDI (Slave Device Input) are together and go to mega pin 51
MISO (Master Input Slave Output) and SDO (Slave Device Output) are together and go to mega pin 52
Each of the CS pins have a 10k resister which pulls high.
MAX uses mega pin 5 for the CS
MicroSD used mega pin 4 for the CS.
I do the normal things to initialize everything.
const int CS_SD = 4;
const int CS_AirProbe = 5;
// use hardware SPI, just pass in the CS pin
Adafruit_MAX31865 maxAirTemp = Adafruit_MAX31865(CS_AirProbe);
// 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
pinMode(53,OUTPUT);
pinMode(CS_SD,OUTPUT);
pinMode(CS_AirProbe,OUTPUT);
/// Make sure all SPI devices on the bus are inactive. HIGH is inactive and LOW is active
digitalWrite(CS_SD,HIGH);
digitalWrite(CS_AirProbe,HIGH);
When I initialized and write to my SD card I always set the pin to low, do my work and then back to high.
void WriteAirTempToLog() {
Serial.println("Writing Temp to Log");
digitalWrite(CS_SD,LOW);
myFile.print ("Air Temp = " );
myFile.println(currAirTemp);
myFile.flush();
digitalWrite(CS_SD,HIGH);
}
When I read temps I always do the same thing.
Serial.print("In ReadAirTemp");
digitalWrite(CS_AirProbe,LOW);
uint16_t rtd = maxAirTemp.readRTD();
Serial.print("RTD value: "); Serial.println(rtd);
float ratio = rtd;
float F,C;
ratio /= 32768;
Serial.print("Ratio = "); Serial.println(ratio,8);
Serial.print("Resistance = "); Serial.println(RREF*ratio,8);
...
digitalWrite(CS_AirProbe,HIGH);
I never set anything to say that the mega is the master.
Here are the results when I have them both plugged in. Notice the MAX gives me null readings.
Initializing Adafruit MAX31865 PT100 Sensor.
Done Initializing Adafruit MAX31865 PT100 Sensor.
Initializing SD card...Wiring is correct and a card is present.
Card type: SD2
Initializing SD card via SD.begin(cs) ...
Volume type is FAT32
Volume size (bytes): 1973350400
Volume size (Kbytes): 1927100
Volume size (Mbytes): 1881
Files found on the card (name, date and size in bytes):
SYSTEM~1/ 2017-11-19 12:57:30
WPSETT~1.DAT 2017-11-19 12:57:30 12
INDEXE~1 2017-11-19 12:57:34 76
RECIPE.TXT 2018-03-31 09:40:42 137
setting cs_sd high
done setting cs_sd high
dataLoggerName =
Done Writing
© SkewerSmoker ... Testing Serial Communications
This demo will send/receive a formulation and parse it
In ReadAirTempRTD value: 32729
Ratio = 0.99880981
Resistance = 429.48822021
Celcius Temperature = -242.02
Farenheit Temperature = -403
Here is the MAX RTD Temp reading if I unplug the MISO line on the SD Card.... It reads fine.
Initializing Adafruit MAX31865 PT100 Sensor.
Done Initializing Adafruit MAX31865 PT100 Sensor.
Initializing SD card...initialization failed. Things to check:
* is a card inserted?
* is your wiring correct?
* did you change the chipSelect pin to match your shield or module?
dataLoggerName =
Done Writing
© SkewerSmoker ... Testing Serial Communications
This demo will send/receive a formulation and parse it
In ReadAirTempRTD value: 8154
Ratio = 0.24884033
Resistance = 107.00134277
Celcius Temperature = 17.93
Farenheit Temperature = 64
Writing Temp to Log
In ReadAirTempRTD value: 8155
Ratio = 0.24887084
Resistance = 107.01446533
Celcius Temperature = 18.00
Farenheit Temperature = 64