Hello there. I am currently working on a project that requires the use of an SD card. I am using a Teensy 3.2 and for a while I couldn’t get the SD card to initialize when it was running at 96MHz. After doing a little research and fiddling, I changed the CPU speed to 24MHz and it works totally fine, which means my wiring and code (which is pasted below) check out. I upgraded to a Teensy 4.0 and it had the same issue: works at 24MHz but not at 600. I’ve tried it with two SD cards using a couple of shields/adapters from Amazon, as well as with the Adafruit SPI SMT SD Card breakout and these all face the same issues. I know a guy who says he can use SD cards just fine with T3.2 at 96MHz, which made me think that reducing the CPU speed is abnormal. Is this the case? If not, how do I fix it? If so, can I bring the CPU speed up to its max in order to take advantage of the higher processing power? Can I run an SD card on an external clock/SCK source that runs at 24MHz while running Teensy at 600MHz?
I am using Teensyduino/Arduino IDE for this project, with the integrated SD and SPI libraries. Working on a Mac (not sure if that changes anything). And this issue goes for any code I use, including examples from the Libraries, not just with the code posted below.
Thanks for your help.
I am using Teensyduino/Arduino IDE for this project, with the integrated SD and SPI libraries. Working on a Mac (not sure if that changes anything). And this issue goes for any code I use, including examples from the Libraries, not just with the code posted below.
Thanks for your help.
Code:
#include <SD.h>#include <SPI.h>
File myFile;
int pinCS = 10;
void setup() {
Serial.begin(9600);
SPI.setMOSI(11);
SPI.setSCK(13);
SPI.setMISO(12);
Serial.print("Initializing SD card...");
pinMode(pinCS, OUTPUT);
delay(1500);
if(!SD.begin(pinCS)) {
Serial.println("Initialization failed!");
return;
} else {
Serial.println("Initialization done.");
}
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
myFile.close();
Serial.println(" Done.");
} else {
Serial.println("error opening test.txt");
}
SD.remove("test.txt");
}
void loop() {
}