Problem MAX31865 and MicroSD card on the same SPI bus

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
2 Likes

Looks like powering issue for me. How SD card and a MAX are powered? Try to use independent power source for MAX board

Post a link to your SD card board. Many cheap Chinese boards are not SPI compatible (work only as a single device on the bus because the don't tri-state the MISO line if CS is HIGH). Some of them can be fixed with a hardware modification but it really depends on the used board.

1 Like

This seems to be the SD card schmatic of OPs SD sheild and as @ pylon said:

pylon:
Post a link to your SD card board. Many cheap Chinese boards are not SPI compatible (work only as a single device on the bus because the don't tri-state the MISO line if CS is HIGH). Some of them can be fixed with a hardware modification but it really depends on the used board.

the chip actually allows tri-state but the manufacturer decide to connect the the 'OE' to GND thereby causing the SPI pins never to be tristated... Would have been better if they had connected 'OE' to the CS input (here GPIO15) :frowning:

1 Like

Thank you to all who replied. My background is software design so my coding skills are much more affluent than my hardware skills. I am blessed to be in the same room as all you hardware experts. I have learned everything on my own and I don't know what I would do without all your help. My geeky friends are laughing saying, "Hey he is talking about SPI hardware architecture" :slight_smile:

As far as the powering issue, I checked it and it holds pretty well as 5v with both running.

I did find this site which explains why I should take better care dealing with the cheap Chinese parts. I spend more time trying to make things work from Chinese parts.

@Sherzaad, could I trouble you with giving me a little more detail on how you can look at this schematic and determine a proper tristate design? What would a good design look like and how can you tell they designed this one wrong? I really want to learn what I am looking for so I can have multiple peripherals work on a single bus.

https://forum.arduino.cc/index.php?topic=465101.0

Finally, Is there a card manufacture that you would recommend that does the Tri-State properly? Obviously Adafruit but are there others? Any links would be very much appreciative. I do not care if it is a microsd or an sd card reader.

bigredsmokehouse:
@Sherzaad, could I trouble you with giving me a little more detail on how you can look at this schematic and determine a proper tristate design? What would a good design look like and how can you tell they designed this one wrong? I really want to learn what I am looking for so I can have multiple peripherals work on a single bus.

If you look at the picture I posted you will see that the chip has a part number (74LVC125APW). If you google it you will likely find the datasheet for it.

And if you go through the Datasheet, well you should be able to understand what state the OE pins need to be to put the output pin in tri-state condition (here they would have to be held HIGH).

Now if you follow the lines in the picture, you will see that all the OE pins are connected to Ground ie logic level LOW

As mentioned before if it were me, I would have connected all the OE pin to CS input so that when CS =HIGH, chip is in tristate condition, when CS=LOW, chip output is enabled for SPI comms

If you feel brave enough to do some soldering I think if you do the following mod to the board, you should be able to use it together with your MAX31865.

All needs doing is remove a resistor, and solder a wire to the the DO pin of the SD card holder to connect DIRECTLY to the MISO pin of your arduino (NOT the pin on the SD Card shield; that pin is not be used after the rework).

GOOD LUCK! :slight_smile:

1 Like

Thank you for the details and I now get it. I appreciate the time you took to explain it. Of course i will be courageous and solder it. The crappy part cost me a whopping $1 and it doesn't work :slight_smile: Thanks again.

1 Like