SD card initialization

lpzma

Member
I am working with a Teensy Board4.1, with an SD card 256 attached to it, and when I run code from the example library (SD card read/write) the Serial Monitor's output is that "initialization failed".
The only information that I found is that the SD card might be to big. Could this be true? Is there a work around?
 
no, I use 1TB card reguralily. the card must be formated as Fat (Fat32 or exFat). Use the latest Teensyduino, as it enables exFAT by default
 
no, I use 1TB card reguralily. the card must be formated as Fat (Fat32 or exFat). Use the latest Teensyduino, as it enables exFAT by default
Any advice as to where I can look to find out how to do that or could you kindly explain please?
 
If you (or other people) have not yet reformatted your SD card, please DO NOT reformat it now. All SD cards come properly formatted. Many people have wasted a lot of their time with reformatting, when the real problem was not card formatting at all. If your card is new, or even well used but never reformatted, then it will have the correct format. But if you (or anyone else) has reformatted the card, then it may have the wrong format.

You can run the CardInfo example to check. If your card as the wrong format, it will identify the card hardware and tell you the card's capacity, but then fail to read it. Only try reformatting if CardInfo detects your card and shows the correct capacity. If CardInfo does not detect your card, the problem is not formatting and time spent reformatting the card will only be wasted effort which adds a lot more uncertainty.

If CardInfo can't see your card and show the capacity, then you may have the wrong CS pin defined in your program, or you may have a hardware problem. Using SD cards on the audio shield, poor quality soldering is by far the most common problem. Using the SD socket on Teensy 4.1, the most common issue is leaving the CS pin at 10, rather than editing to BUILTIN_SDCARD. See the comments in those SD examples for details.

There is also a rare problem with very old SD cards (measured in MB rather than GB - you said only "256" and didn't tell us if MB or GB) in the Teensy 4.1 socket. This only applies with SDIO used by the Teensy 4.1 socket. SPI used by the audio shield doesn't have this issue. It has been fixed in the latest beta code. If you are using a very old card and the SD socket on Teensy 4.1, use Arduino 2.2.1 Boards Manager to install Teensy 0.59.4. You might also just get a new card. All modern cards measured in GB work fine. A brand new card will also be certain to come with correct formatting.

Another problem we sometimes see if use of non-PJRC adaptor boards which have a slow buffer chip. Some of those adpators say they work with 3.3V power, but actually have a voltage regulator that can't properly power the card with 3.3V unless you give it 5V input. It is usually possible to make low quality SPI adaptor boards work if the power is correct and if you use special syntax to tell Teensy to use a slower clock.

If this still doesn't resolve your problem, please understand we need to be able to see what you're really doing. Screenshots and photos are best. Sometimes we get problems that are a misunderstanding, where words describing what as done always say the correct thing, but when we see photos of what was actually done, the misunderstanding about those words becomes apparent.

Please consider, I had to write a longer message to try helping, because I can't see how you're connecting the SD card. I want to help. Please, if you still have problems, spend a few minutes to show photos and give precise info about the card and any other hardware you're using, so we can really see what you're actually doing.
 
Last edited:
Can you upload a photo of the arrangement you want to use with your Teensy 4.1 board? So we can give you an idea of the problem you are experiencing.
 
The micro SD is 256 GB.
The two Teensy Boards 4.1 that I have are brand new out of the box and came with the SD card option already installed.
I am using Arduino IDE 2.2.1
Could this be a hardware defect?
 
Can you upload a photo of the arrangement you want to use with your Teensy 4.1 board? So we can give you an idea of the problem you are experiencing.
Thank you for replying and wanting to help! Yes, I can upload some pictures, but I am leaving for vacation and will not be back until the week of the January 8th.
 
Could this be a hardware defect?

Hardware defect is always possible, but pretty unlikely in this case. Every Teensy 4.1 goes through a test which checks all pins. The test fixture has a little SD-shaped PCB on an 8 pin flat cable, so it really does test the SD socket is electrically connected. The SD socket's pins are pretty well protected by its metal frame. You can check if the SD card works by using it with a PC. Hardware failure is pretty unlikely.

More likely explanation is a simple mistake, like leaving the CS pin at 10 (the default value in all the SD library examples) rather that editing the code to BUILTIN_SDCARD (as explained in the comments on that code).

I can confirm 256GB cards definitely do work. I have a couple of them here, and even one 512GB. Several people have confirmed 1TB cards also work fine.
 
Thanks Paul!
I just found your example using SD.begin(chipSelect) I am going to give that code a try and see if good things happen.
 
Hardware defect is always possible, but pretty unlikely in this case. Every Teensy 4.1 goes through a test which checks all pins. The test fixture has a little SD-shaped PCB on an 8 pin flat cable, so it really does test the SD socket is electrically connected. The SD socket's pins are pretty well protected by its metal frame. You can check if the SD card works by using it with a PC. Hardware failure is pretty unlikely.

More likely explanation is a simple mistake, like leaving the CS pin at 10 (the default value in all the SD library examples) rather that editing the code to BUILTIN_SDCARD (as explained in the comments on that code).

I can confirm 256GB cards definitely do work. I have a couple of them here, and even one 512GB. Several people have confirmed 1TB cards also work fine.
Paul,

Thank you for replying! I have tried to modify the code so that it matches the schematic, but I still have not been able to access the SD card. Can you please share with me your code?
 
I have tried to modify the code so that it matches the schematic, but I still have not been able to access the SD card. Can you please share with me your code?

Before I reply, can you tell show me this schematic you've mentioned? Or show a photo of how your SD card is connected?

Or if the SD card is simply inserted into the SD socket on your Teensy 4.1, that's fine. Just please clearly say this. I need to know how your SD card is really connected.
 
I was able to do a Quick reformat that @KurtE provided, thank you. I am trying to read and write .txt files to the SD card, but I am not able to do it.
I also tried to try out the example library "ReadWrite" and nothing come out on the serial monitor. When I type to send a message to the teensy board there is file but when I try to open it nothing happens.
Would it be possible to set up a 1:1 with someone?
 
Again please post, exact copy of the example sketch you say is failing, preferably within the code tags: </> button on top.
Also please post image of your board.

Little things matter, like: did you update the example sketch to use the correct chip select.
Which library you are using. Again how is it configured, which the sketch should show).

When you formatted the disk for quick format, which format did it choose? Fat32 or ExFat. 128gb is sort of the borderline between when it defaults to one or the other.

If you are using SDFat versus SD, than, you have the options of choosing a FS that supports only FAT32, one that only supports ExFat or one that supports both. So again maybe a mismatch problem.
 
I think at this point it would be easier if someone could share what they are using. I thought it would have been to just buy an SD card, plug, and play. But for some reason it is just not that easy. If someone could kindly share what they are using to access an SD card for a Teensy 4.1 it would be a big help.
Thank you
 
This works for me using Arduino 1.8.19 and TeensyDuino 1.59b3

1) Insert new 32GB Sandisk Ultra SD card into T4.1 SD socket
2) From Arduino IDE, open SD example program CardInfo
3) Change line 40 from "chipSelect = 10" to "chipSelect = BUILTIN_SDCARD"
4) Confirm Arduino is configured to build for Teensy 4.1
5) Build and run
6) Serial Monitor output shown below

Code:
Initializing SD card...Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (Kbytes): 31154688
Volume size (Mbytes): 30424
 
This works for me using Arduino 1.8.19 and TeensyDuino 1.59b3

1) Insert new 32GB Sandisk Ultra SD card into T4.1 SD socket
2) From Arduino IDE, open SD example program CardInfo
3) Change line 40 from "chipSelect = 10" to "chipSelect = BUILTIN_SDCARD"
4) Confirm Arduino is configured to build for Teensy 4.1
5) Build and run
6) Serial Monitor output shown below

Code:
Initializing SD card...Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (Kbytes): 31154688
Volume size (Mbytes): 30424
Thank you very much, I will try this. Did you have to format the SD card?
 
Back
Top