SD won’t initialize at high CPU speed.

Status
Not open for further replies.

Haymyke

New member
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.

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() {
 
}
 
Use adapters without electronic on it. These are needless levelshifters (for 5V Arduinos) which are often too slow for Teensy.
Then, use very short connections.
 
So you suggest getting a breakout with as little electronics on it as possible because the levelshifters (which I understand is what changes the voltage from 5V to 3.3V) interfere with the function of the SD card? Ok. And short connections because SPI is better over short distances. Will this Adafruit SD Card Breakout suffice since it doesn’t have that voltage regulator on it (their website says in the second to last paragraph “ there's no level shifting or power regulator”)? If not, what would you suggest?

Thanks so much!
 
So you suggest getting a breakout with as little electronics on it as possible because the levelshifters (which I understand is what changes the voltage from 5V to 3.3V) interfere with the function of the SD card? Ok. And short connections because SPI is better over short distances. Will this Adafruit SD Card Breakout suffice since it doesn’t have that voltage regulator on it (their website says in the second to last paragraph “ there's no level shifting or power regulator”)? If not, what would you suggest?

Thanks so much!

Yes, that board looks good.
Or, use the audio shield.
 
Since the SPI clock during initialization is supposed to be under 400KHz, a slow interface isn't going to be a problem at that stage.
 
Status
Not open for further replies.
Back
Top