SD card data logging with EVAL-CN0391-ARDZ shield via SPI?

I bought a Eval-CN3091-ARDZI and tried it out with my Arduino Uno board with the sample code without any issue.     My SD card (integrated into a TFT LCD shied) works fine with the Uno borad.  But the SD card stopped working when stack the TFT on top of the Eval-CN3091-ARDZ shield.  It works when place the shunt to 3 and 4 position (instead of 1 and 2) and I code the Slave Select pin to 8 (instead of the default 10).   

The issue I am having now is that I can not have CN3091 board and my SD card communicating via SPI  in a way so that  log themocouple readings are logged in my SD card.  The AD7124 user guide does clearly state which shunt position is corresponding to which slave Select Pin in Arduino board.

Any thought on why and any possible solutions?

#include <SPI.h>
#include "CN0391.h"
#include "Communication.h"
// include the SD library:
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
File dataFile;
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 8;

//#define SS 10 //ss

void setup() {
    Serial.begin(9600);
     while (!Serial) {
      ; // wait for serial port to connect. Needed for Leonardo only
    }
pinMode(4, OUTPUT);
pinMode(10, OUTPUT);
SPI.begin();

    Serial.print("Initializing SD card...");
    // make sure that the default chip select pin is set to
    // output, even if you don't use it:
    pinMode(SS, OUTPUT);

    // see if the card is present and can be initialized:
    if (!SD.begin(chipSelect)) {
      Serial.println("Card failed, or not present");
      // don't do anything more:
      while (1) ;
    }
    Serial.println("card initialized.");

    }

delay(1000);
Serial.println("\nThermo Couple Starts: ");
digitalWrite(8,HIGH); //disable device

delay(1000);
//pinMode(CS_PIN, OUTPUT);
SPI.begin();
pinMode(SS, OUTPUT);
     SPI.setDataMode(SPI_MODE3); //CPHA = CPOL = 1    MODE = 3
     delay(1000);
   CN0391_init();

#if(USE_RTD_CALIBRATION == YES)
   CN0391_calibration(RTD_CHANNEL);
   Serial.println(F("RTD channel calibration completed!"));
#else
   Serial.println(F("Calibration for RTD channel is disabled."));
#endif

#if(USE_TH_CALIBRATION == YES)
   CN0391_calibration(TH_CHANNEL);
   Serial.println(F("TC channel calibration completed!"));
#else
   Serial.println(F("Calibration for TC channel is disabled."));
#endif
delay(10000);
   CN0391_set_data();
   Serial.println("test");
   CN0391_display_data();

}

void loop() {

}



add sketch
[edited by: ystan at 8:12 PM (GMT 0) on 28 Feb 2019]
  • Hi,

    I am moving this thread to Reference Circuits as they may have better understanding regarding the circuit board and configuration. If you find any issue specific to AD7124, feel free to post it again to Precision ADC.   

    Thanks,

    Jellenie

  • Hi,

    So it makes sense that the boards stacked on top of each other don't work initially because they share the same chip select pin.  So you did the correct thing in moving the jumper position on the EVAL-CN0391-ARDZ (thats why we added that flexibility).

    The problem you are having now is that you need to read SPI data from the CN0391 onto the Arduino Uno, and then you need to write SPI data back out to the SD card.  You are going to need to create another variable or array to capture the incoming temperature data, and store that on the Arduino.  Once you have x number of samples, you'll want to stop reading the CN0391 and then write those temperature values to the SD card.

    You can only address one SPI device at a time so this is why you are currently having issues.

    Good Luck.

    Brandon