Teensy 3.5: how to use SPI pins and built in SD card at the same time?

Status
Not open for further replies.

jagerton

New member
Howdy!

I'm attempting to use some TLC1543CN ADCs with the Teensy 3.5 and record their conversions to an SD card file to monitor some outputs on an experimental aircraft I'm working on. I've managed to create a separate program that can save values from the Teensy's built in analog pins, and a separate program that can read the ADCs through SPI. But when I tried to combine those two together, the program halts. I'm working on a Windows 10 (64 bit) computer with the Arduino IDE 1.8.12. I'm also using the standard SPI.h and SD.h libraries, which should be using the hardware versions rather than the default arduino versions.

The code should initialize everything, check its EEPROM for a number that it uses to create a file name string ("filename0" for example), then check that file name against files in the SD card using SD.exists("filename0"). If it doesn't exist, it will open a file with that name and write the beginning of a csv file. If it does exist, it opens a file with a number one higher (i.e. "filename1") and writes the start of the csv file. Then, every loop it should read every channel from the ADCs over SPI and save the conversions into an array. Then it takes the array and saves it as a comma separated line into the SD card file.

I think the problem is that it can't initialize the SD card to begin with, but for some reason thinks it has successfully initialized the SD card. This is because it has not been correctly identifying if files already exist on the SD card. The program then halts as it attempts to write the array into the SD card.

I think the problem is how I am using SPI and that the SD card library must also use the SPI, but switching from SPI.begin() to SPI1.begin() didn't seem to solve the issue. I think either my syntax is incorrect, my understanding of the SPI/SD card system is incorrect, or my program is flawed at some step during the saving process - or maybe it's some combination of the three.

From what I've read, I think it should be possible to use the SPI pins and the SD card one after the other (as I have attempted) but clearly I've missed a step. Could someone help me understand why my code is failing? Or at least explain how I would use the SPI pins and the SD card in the same program?

Here is the code:
Code:
#include <SPI.h>
#include <SD.h>
#include <EEPROM.h>

const int SampleFrequency = 10;
const int channels = 14;
const char *Headers[] = { "Time (ms)", "ADC1_0", "ADC1_1", "ADC1_2", "ADC1_3",    // This array is the header for the comma separated list this code creates
                 "ADC1_4", "ADC1_5", "ADC1_6", "ADC1_7", "ADC1_8", "ADC1_9", 
                 "ADC1_10", "ADC2_0", "ADC2_1", "ADC2_2", "ADC2_3", "ADC2_4",
                 "ADC2_5", "ADC2_6", "ADC2_7", "ADC2_8", "ADC2_9", "ADC2_10" };

const int chips[] = {15, 9};

const int chipSelect = BUILTIN_SDCARD;
const int ledPin = 13;
bool led = HIGH;
bool canWrite = true;

int lastIndex = 0;

String fileName;
File myFile;

unsigned long currentMillis = 0;
int Array[22];
int SampleNum;


void setup() {
  pinMode(ledPin, OUTPUT);
  
  //set chip select pins to output
  pinMode(chips[0], OUTPUT);
  digitalWrite(chips[0], HIGH);
  pinMode(chips[1], OUTPUT);
  digitalWrite(chips[1], HIGH);

  Serial.begin(115200);


  //Initialize SD card
  if(!SD.begin(chipSelect)){
    Serial.println("Initialization failed!");
    canWrite = false;
    return;
  }


  //Initialize SPI
  //SPI.setSCK(27);
  //SPI.setMOSI(0);
  //SPI.setMISO(1);
  SPI.begin();

  fileName = checkLastIndex();
  checkFileExists(fileName);
  openFile(fileName);

  SampleNum = channels*((sizeof(chips))/(sizeof(chips[0])));
}

void loop() {
  currentMillis = millis();

  if(canWrite){
    if(currentMillis % SampleFrequency == 0){
      //Sample the analog Values and write them to the file ...
      gatherCurrentDataIntoArray();
      canWrite = saveCurrentData(fileName);
      
      led = !led;
      digitalWrite(ledPin, led);
    }
  }else{
    SD_SOS();
  }
}

String checkLastIndex(){
  Serial.println("Index after restart: ");
  lastIndex = EEPROM.read(0);
  Serial.println(lastIndex);

  String fN = "LogFile";
  fN += lastIndex;
  
  return fN;
}

void checkFileExists(String fName){  
  char fileN[fName.length() + 1];
  fName.toCharArray(fileN, fName.length() + 1);

  if(!SD.exists(fileN)){
    String string = "The file [";
    string += fileName;
    string += "] does not exist and will be created.";
    Serial.println(string);
  }else{
    String string = "The file[";
    string += fileName;
    string += "] already exists!";
    Serial.println(string);

    // Changing index in EEPROM
    lastIndex = lastIndex + 1;
    EEPROM.update(0, lastIndex);

    fileName = checkLastIndex();
  }
}

void openFile(String fileName){
  char fileN[fileName.length() + 1];
  fileName.toCharArray(fileN, fileName.length() + 1);
  
  Serial.print("Opening new file with name [");
  Serial.print(fileN);
  Serial.print("] ...");
  
    myFile = SD.open(fileN, FILE_WRITE);
    for(int i = 0; i <= SampleNum; i++){
      if(i == SampleNum){
        myFile.println(Headers[i]);
      }else{
        myFile.print(Headers[i]);
        myFile.print(",");
      }
    }
    myFile.close();
    
  Serial.println(" done.");
}

void gatherCurrentDataIntoArray(){
  Serial.print("\t");
  for(int i = 0; i < SampleNum/channels; i++){
    int ArrayOffset = i * channels;
    for(byte chan = 0; chan <= channels; chan++){
      if(chan == 0){
        //First round returns previous conversion, prefill with channel 0
        GetAnalog(chips[i],0);                    
      }else if(chan == channels){
        Serial.print(i);
        Serial.print("_");
        Serial.print(chan-1, HEX);
        Serial.print(":");
        int j = (i != SampleNum/channels - 1) ? i + 1 : 0;
        int value = GetAnalog(chips[j], 0);
        if(i == SampleNum/channels - 1){
          Serial.println(value);
        }else{
          Serial.print(value);
        }
        Array[ArrayOffset + chan - 1] = value;
      }else{
        Serial.print(i);
        Serial.print("_");
        Serial.print(chan-1, HEX);
        Serial.print(":");
        int value = GetAnalog(chips[i], chan);
        Serial.print(value);
        Serial.print(" ");
        Array[ArrayOffset + chan - 1] = value;
      }
    }
  }
}

//x(n) = value of channel n; GetAnalog(CS, n) = x(n-1)
int GetAnalog(int CS, byte n){
  SPI.beginTransaction(SPISettings(210000, MSBFIRST, SPI_MODE0));
  digitalWrite(CS, LOW);
  word value;
  value = SPI1.transfer16(n<<12);
  digitalWrite(CS, HIGH);
  SPI.endTransaction();
  return value>>5;
}

bool saveCurrentData(String fileName){
  char fileN[fileName.length() + 1];
  fileName.toCharArray(fileN, fileName.length() + 1);

  Serial.print("Saving: ");
  Serial.print(currentMillis);
  Serial.print(",");
  for(int i = 0; i < SampleNum; i++){
    Serial.print(Array[i]);
    Serial.print(",");
  }
  Serial.print(" : to ");
  Serial.println(fileN);

  myFile = SD.open(fileN, FILE_WRITE);
  //Time
  Serial.print(".");
  if(!myFile.print(currentMillis)){
    myFile.close();
    return false;
  }
  Serial.print(".");
  if(!myFile.print(",")){
    myFile.close();
    return false;
  }
  Serial.print(".");
  //the rest of the array
  for(int i = 0; i < SampleNum; i++){
    if(i == SampleNum - 1){
      Serial.print(".");
      //Last entry, add an endline
      if(!myFile.println(Array[i])){
        myFile.close();
        return false;
      }
    }else{
      Serial.print(".");
      if(!myFile.print(Array[i])){
        myFile.close();
        return false;
      }
      if(!myFile.print(",")){
        myFile.close();
        return false;
      }
    }
  }
  myFile.close();

  Serial.print(" Done.");

  return true;
}

And the IDE console when compiling:
Code:
C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\jagerton\Documents\Arduino\libraries -fqbn=teensy:avr:teensy35:usb=serial,speed=120,opt=o2std,keys=en-us -ide-version=10812 -build-path C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504 -warnings=none -build-cache C:\Users\jagerton\AppData\Local\Temp\arduino_cache_416271 -verbose C:\Users\jagerton\Documents\Arduino\Scripts\BlackBox\ADCBlackBox\sketch_may28a\sketch_may28a.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\jagerton\Documents\Arduino\libraries -fqbn=teensy:avr:teensy35:usb=serial,speed=120,opt=o2std,keys=en-us -ide-version=10812 -build-path C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504 -warnings=none -build-cache C:\Users\jagerton\AppData\Local\Temp\arduino_cache_416271 -verbose C:\Users\jagerton\Documents\Arduino\Scripts\BlackBox\ADCBlackBox\sketch_may28a\sketch_may28a.ino
Using board 'teensy35' from platform in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr
Using core 'teensy3' from platform in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr
Detecting libraries used...
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=151 -DARDUINO=10812 -DARDUINO_TEENSY35 -DF_CPU=120000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\cores\\teensy3" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\sketch\\sketch_may28a.ino.cpp" -o nul
Alternatives for SPI.h: [SPI@1.0]
ResolveLibrary(SPI.h)
  -> candidates: [SPI@1.0]
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=151 -DARDUINO=10812 -DARDUINO_TEENSY35 -DF_CPU=120000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\cores\\teensy3" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SPI" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\sketch\\sketch_may28a.ino.cpp" -o nul
Alternatives for SD.h: [SD@1.2.4 SD@1.2.2]
ResolveLibrary(SD.h)
  -> candidates: [SD@1.2.4 SD@1.2.2]
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=151 -DARDUINO=10812 -DARDUINO_TEENSY35 -DF_CPU=120000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\cores\\teensy3" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SPI" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SD" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\sketch\\sketch_may28a.ino.cpp" -o nul
Alternatives for EEPROM.h: [EEPROM@2.0]
ResolveLibrary(EEPROM.h)
  -> candidates: [EEPROM@2.0]
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=151 -DARDUINO=10812 -DARDUINO_TEENSY35 -DF_CPU=120000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\cores\\teensy3" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SPI" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SD" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\EEPROM" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\sketch\\sketch_may28a.ino.cpp" -o nul
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI\SPI.cpp
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\File.cpp
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\SD.cpp
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\cache_t3.cpp
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\card_t3.cpp
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\dir_t3.cpp
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\fat_t3.cpp
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\file_t3.cpp
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\init_t3.cpp
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\utility\NXP_SDHC.cpp
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\utility\Sd2Card.cpp
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\utility\SdFile.cpp
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\utility\SdVolume.cpp
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\EEPROM\EEPROM.cpp
Generating function prototypes...
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=151 -DARDUINO=10812 -DARDUINO_TEENSY35 -DF_CPU=120000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\cores\\teensy3" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SPI" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SD" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\EEPROM" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\sketch\\sketch_may28a.ino.cpp" -o "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"C:\\Program Files (x86)\\Arduino\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/precompile_helper" "C:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr/cores/teensy3" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504" "C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -x c++-header -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=151 -DARDUINO=10812 -DARDUINO_TEENSY35 -DF_CPU=120000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr/cores/teensy3" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504/pch/Arduino.h" -o "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504/pch/Arduino.h.gch"
Using previously compiled file: C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504\pch\Arduino.h.gch

"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=151 -DARDUINO=10812 -DARDUINO_TEENSY35 -DF_CPU=120000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504/pch" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\cores\\teensy3" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SPI" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SD" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\EEPROM" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\sketch\\sketch_may28a.ino.cpp" -o "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\sketch\\sketch_may28a.ino.cpp.o"
Compiling libraries...
Compiling library "SPI"
Using previously compiled file: C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504\libraries\SPI\SPI.cpp.o
Compiling library "SD"
Using previously compiled file: C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504\libraries\SD\File.cpp.o
Using previously compiled file: C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504\libraries\SD\SD.cpp.o
Using previously compiled file: C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504\libraries\SD\cache_t3.cpp.o
Using previously compiled file: C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504\libraries\SD\card_t3.cpp.o
Using previously compiled file: C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504\libraries\SD\dir_t3.cpp.o
Using previously compiled file: C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504\libraries\SD\fat_t3.cpp.o
Using previously compiled file: C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504\libraries\SD\file_t3.cpp.o
Using previously compiled file: C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504\libraries\SD\init_t3.cpp.o
Using previously compiled file: C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504\libraries\SD\utility\NXP_SDHC.cpp.o
Using previously compiled file: C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504\libraries\SD\utility\Sd2Card.cpp.o
Using previously compiled file: C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504\libraries\SD\utility\SdFile.cpp.o
Using previously compiled file: C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504\libraries\SD\utility\SdVolume.cpp.o
Compiling library "EEPROM"
Using previously compiled file: C:\Users\jagerton\AppData\Local\Temp\arduino_build_275504\libraries\EEPROM\EEPROM.cpp.o
Compiling core...
Using precompiled core: C:\Users\jagerton\AppData\Local\Temp\arduino_cache_416271\core\core_576b67285ecb01e18963173d351aed2d.a
Linking everything together...
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-gcc" -O2 -Wl,--gc-sections,--relax,--defsym=__rtc_localtime=1590763101 "-TC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\cores\\teensy3/mk64fx512.ld" -lstdc++ -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -o "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504/sketch_may28a.ino.elf" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\sketch\\sketch_may28a.ino.cpp.o" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\libraries\\SPI\\SPI.cpp.o" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\libraries\\SD\\File.cpp.o" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\libraries\\SD\\SD.cpp.o" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\libraries\\SD\\cache_t3.cpp.o" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\libraries\\SD\\card_t3.cpp.o" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\libraries\\SD\\dir_t3.cpp.o" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\libraries\\SD\\fat_t3.cpp.o" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\libraries\\SD\\file_t3.cpp.o" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\libraries\\SD\\init_t3.cpp.o" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\libraries\\SD\\utility\\NXP_SDHC.cpp.o" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\libraries\\SD\\utility\\Sd2Card.cpp.o" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\libraries\\SD\\utility\\SdFile.cpp.o" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\libraries\\SD\\utility\\SdVolume.cpp.o" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504\\libraries\\EEPROM\\EEPROM.cpp.o" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504/..\\arduino_cache_416271\\core\\core_576b67285ecb01e18963173d351aed2d.a" "-LC:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504" -larm_cortexM4lf_math -lm
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504/sketch_may28a.ino.elf" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504/sketch_may28a.ino.eep"
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-objcopy" -O ihex -R .eeprom "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504/sketch_may28a.ino.elf" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504/sketch_may28a.ino.hex"
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/stdout_redirect" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504/sketch_may28a.ino.lst" "C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-objdump" -d -S -C "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504/sketch_may28a.ino.elf"
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/stdout_redirect" "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504/sketch_may28a.ino.sym" "C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-objdump" -t -C "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504/sketch_may28a.ino.elf"
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/teensy_post_compile" -file=sketch_may28a.ino "-path=C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504" "-tools=C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/" -board=TEENSY35
Multiple libraries were found for "SD.h"
 Used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD
 Not used: C:\Program Files (x86)\Arduino\libraries\SD
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI 
Using library SD at version 1.2.2 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD 
Using library EEPROM at version 2.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\EEPROM 
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-size" -A "C:\\Users\\jagerton\\AppData\\Local\\Temp\\arduino_build_275504/sketch_may28a.ino.elf"
Sketch uses 30644 bytes (5%) of program storage space. Maximum is 524288 bytes.
Global variables use 5900 bytes (2%) of dynamic memory, leaving 256236 bytes for local variables. Maximum is 262136 bytes.
From my best guess and a cursory glance, the libraries should be loading from the hardware folder rather than default arduino, which I also think is correct since I'm using the Teensy 3.5.

And here is the serial output after uploading to the Teensy 3.5:
Capture.PNG
It should continue scrolling as it reads and saves data from the ADC, but it just halts here.

The Teensy is taking its power from the computer and I'm powering the ADCs and providing a test voltage for them to read with my Analog Discovery 2:
Teensy2.jpg

Thanks in advance!
 
One minor problem with your sketch is your file names are too long. SD lib filenames are in 8.3 format, so "name" is max of 8 characters with optional . and 3 character extension.

The major problem and why it halts is you have value = SPI1.transfer16(n<<12); that should read value = SPI.transfer16(n<<12);

I also suspect your Array[] subscripts grow larger than 21. try printing ArrayOffset + chan - 1 before each Array assignment

There may be other bugs ....
 
With T_3.5 and chipSelect = BUILTIN_SDCARD; it is using an SDIO bus for the SD card with no SPI conflict or common pin connections/hardware.
 
Thanks for the file name size tip, I decided to shorten the name to something that wouldn't ever grow above 8 characters long.

I also went over my code with a fine toothed comb (after taking the weekend to step away) and I've gotten it working. I think I agree that it was a problem with some function attempting to access parts of Array[] that were outside its bounds.
 
Status
Not open for further replies.
Back
Top