SPI conflict with Uno, Ultimate GPS Logger, and Thermocouple Multiplexer

Hi all,

I’ve been working on this project for a few weeks now, and while I’ve made some progress, I’ve hit a wall. I am fairly new to arduino, so the answer here may be simple, but I’m just not seeing it.

I am attempting to combine an Arduino Uno, an Adafruit Ultimate GPS Logger, and a Ocean Controls Thermocouple Multiplexer. I have been able to get each shield working properly on its own with the arduino, but when I attempt t combine them, they do not function properly. The FAQ for the thermocouple multiplexer states this:
You can’t use SPI and Bit-Banging at the same time. The Adafruit SD library supports Bit-Banging for SD card like this SD.begin(chipSelect, 11, 12, 13); so you will need to download Adafruit’s SD library from here:
https://github.com/adafruit/SD/archive/master.zip

There are also a number of other threads on similar topics, both on this board and others. I’ve attempted the solutions posted there, but I haven’t been able to get the thing to work.

Currently, the largest hurdle I have is that I am unable to reliably initialize the SD card when the thermocouple shield is installed. The thermocouple uses bit-banged SPI to communicate with the arduino, so initially my problem was that I was attempting to use SPI communications to the SD card, and bit-banged SPI to talk to the thermocouple shield, which I’ve since found out are incompatible with each other.

Due to information I found in one of the threads linked above, I switched to the SdFat library from the adafruit SD library in an effort to avoid SPI conflicts. I went into the SdFatConfig.h file and enabled the USE_SOFTWARE_SPI switch to accomplish the same result as what the FAQ suggested, but I think I am still having the same issue as the symptoms are the same.

As a troubleshooting measure, I wrote/borrowed/mangled a simple sketch to talk to the SD card, which looks like this:

#include <SdFat.h>


SdFat sd;
SdFile myFile; //data output file


//-----SD Variable Definitions-----
#define SDPINCS 10 //SD Chip Select

char i; //general use integer
String buf; //general use string

void setup()
{
//-----Open serial communications-----
  Serial.begin(9600);

  
  Serial.print("Initializing SD Card...\r\n");
  
  
  if (!sd.begin(SDPINCS, SPI_HALF_SPEED)) sd.initErrorHalt();
  Serial.println("SD initialization done.");

  if (!myFile.open("test.txt",O_RDWR | O_CREAT | O_AT_END)) {
    sd.errorHalt("opening test.txt for write failed");
  }
  
  myFile.println("Temp0,Temp1,Temp2,Temp3,Temp4,Temp5,Temp6,Temp7"); 
  myFile.close();
}



void loop()
{
  if (millis()<10000){//Temporary limit for debugging
    Serial.print("\n");

    for (i=0;i<8;i++){
      Serial.print(millis()); //used as an example to debug instead of temperatures, below.
      Serial.print(","); //used as an example to debug instead of temperatures, below.
      myFile.print(millis()); //used as an example to debug instead of temperatures, below.
      myFile.print(","); //used as an example to debug instead of temperatures, below.
    }
    Serial.print("\n");
    myFile.print("\n");

    delay(1000);
  
  }
  else{
    myFile.close();
    Serial.println("Data file closed.");

  }
}

With the thermocouple shield absent, it works fine. With it installed, the data looks like this (multiple runs prompted by pressing the “reset” button):

Initializing SD Card...
Can't access SD card. Do not reformat.
No card, wrong chip select pin, or SPI problem?
SD errorCode: 0X1,0X0
Initializing SD Card...
Can't access SD card. Do not reformat.
SD errorCode: 0X8,0X1
Initializing SD Card...
Can't access SD card. Do not reformat.
SD errorCode: 0X8,0X1
Initializing SD Card...
Can't access SD card. Do not reformat.
SD errorCode: 0X4,0X4
Initializing SD Card...
Can't access SD card. Do not reformat.
SD errorCode: 0XF,0X7F
Initializing SD Card...
SD initialization done.

56,56,57,57,57,57,58,58,

1058,1058,1059,1059,1059,1060,1060,1061,

2062,2062,2063,2063,2063,2064,2064,2065,

3065,3065,3066,3066,3066,3067,3067,3068,

4069,4069,4070,4070,4070,4071,4071,4072,

5072,5072,5073,5073,5073,5074,5074,5075,

6076,6076,6077,6077,6078,6078,6078,6079,

7079,7079,7080,7080,7081,7081,7081,7083,

8083,8083,8084,8084,8085,8085,8085,8086,

9086,9086,9088,9088,9089,9089,9089,9090,
Data file closed.

The inconsistent error codes and intermittent functionality lead me to believe that there is some sort of conflict. I would really appreciate any insight that anyone might have on this problem. Thanks!

Which CS pin do you have selected on the Thrermocouple Mux: 8, 9, or 10?

Does the logger shield use Pin 4, 5, 6, or 7 for anything?

Hi John, thanks for the response. The CS pin on the thermocouple mux is pin 9. The GPS logger shield doesn’t use 4,5,or 6 for anything, but 7 is used as the TX pin for the soft serial GPS communication.

I’ve also made some progress since yesterday. I’ve now managed to get the card initializing reliably, and even managed to read and log temperature data, though it is very, very slow.

The solution was to bring down the CS pin for the thermocouple and bring up the CS pin for the SD card when I wanted to use the SD, and then do the reverse for using the thermocouple mux.

#include <SdFat.h>
SdFat sd;
SdFile myFile;


//-----SD Variable Definitions-----
#define chipSelect 10 //SD Chip Select
#define PINEN 7 //MUX Enable Pin

char i; //general use integer
String buf; //general use string

void setup()
{
//-----Open serial communications-----
  Serial.begin(9600);
  pinMode(chipSelect, OUTPUT);
  pinMode(PINEN,OUTPUT);
  
  digitalWrite(chipSelect,LOW);
  digitalWrite(9,HIGH);
  digitalWrite(PINEN, LOW);   // MUX enable off
 
  
  Serial.print("Initializing SD Card...\r\n");
  

  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
  
  Serial.println("SD initialization done.");
  
  if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
    sd.errorHalt("opening test.txt for write failed");
  }

  Serial.print("Writing to test.txt...");
  myFile.println("testing 1, 2, 3.");

  // close the file:
  myFile.close();
  Serial.println("done.");
}



void loop()
{
  if (millis()<10000){//Temporary limit for debugging
    Serial.print("\n");

    if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
    sd.errorHalt("opening test.txt for write failed");
    }

    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");

    // close the file:
    myFile.close();
    Serial.println("done.");

    delay(1000);
  
  }
  
  
}

The important bit is this:

  pinMode(chipSelect, OUTPUT);
  pinMode(PINEN,OUTPUT);
  pinMode(PINCS,OUTPUT);
  
  digitalWrite(chipSelect,LOW); //Bring up SD board (CS Switch)
  digitalWrite(PINCS,HIGH); //Bring DOWN Thermoouple Board (CS Switch)
  digitalWrite(PINEN, LOW);   // MUX enable off

It should be noted that in order to get this to work, I had to set the #define USE_SOFTWARE_SPI flag to 1 from 0 in the file SdFatConfig.h within the SdFat library. I assume SD.begin(chipSelect,11,12,13) would perform a similar task in the adafruit SD library.