Teensy 4.0 and SD card issues.

Status
Not open for further replies.

FLL-Freak

Member
I connected an AdaFruit 3V3 only SD card breakout board to the Teensy4 using individual wires. I used the unpopulated pads on the back of the Teensy4 connecting like wire names between. The only exception being the card detect on the breakout board was left unpopulated.

I am running on Ubuntu Linux. I had Arduino IDE 1.8.12 installed and properly functioning. I can compile programs for Uno, and ESP32 with no trouble.

I then installed the Teensyduino without issue. I am able to compile simple LED blink type programs and have them run on the Teensy4.

I then downloaded the SdFat-beta from githup and installed that from suggestion on a thread in this forum.

Side Note: Arduino on Linux does not like symbolic links. I had tried to just put a symlink called SdFat to SdFat-beta rather than renaming and moving the files. This does not work at all. I also have found this to be a problem trying to give serial ports unique names using udev rules.

Now come my problems.

From the Arduino IDE File...Examples..SD I picked the SdInfo project. This seems to obviously use SdFat as it is called out as a header file. I made NO changes to it and went to run it on a freshly formatted Kingston 8G Micro SD card. Randomly I will get one of two answers from the code:

1) Version 1

Code:
SdFat version: 2.0.0

Assuming an SDIO interface.

type any character to start
init time: 147 ms

Card type: SDHC

Manufacturer ID: 0X2
OEM ID: TM
Product: SA08G
Version: 1.3
Serial number: 0X1DC5AC38
Manufacturing date: 1/2014

cardSize: 7742.69 MB (MB = 1,000,000 bytes)
flashEraseSize: 128 blocks
eraseSingleBlock: true

OCR: 0XC0FF8000

SD Partition Table
part,boot,bgnCHS[3],type,endCHS[3],start,length
1,0X0,0X82,0X3,0X0,0XB,0X53,0XE6,0XAD,8192,15114240
2,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0,0
3,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0,0
4,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0,0

volumeBegin failed. Is the card formatted?
SD errorCode: SD_CARD_ERROR_READ_FIFO = 0X1A
SD errorData = 0X0

type any character to start

2) Second output
Code:
type any character to start
init time: 7 ms

Card type: SDHC

Manufacturer ID: 0X2
OEM ID: TM
Product: SA08G
Version: 1.3
Serial number: 0X1DC5AC38
Manufacturing date: 1/2014

cardSize: 7742.69 MB (MB = 1,000,000 bytes)
flashEraseSize: 128 blocks

eraseSingleBlock: true

OCR: 0XC0FF8000

read MBR failed.

type any character to start

Next step was to load the sample project CardInfo. This project does not seem use the SdFat library as only the SD.h and SPI.h are included at the top of the file. Also a forced error in the SdFatConfig.h file does not cause a compiler error. For this example I edited the chipSelect line to set it to BUILTIN_SDCARD (around line 40). This compiles but only produces the following output:

Code:
Initializing SD card...initialization failed. Things to check:
* is a card inserted?
* is your wiring correct?
* did you change the chipSelect pin to match your shield or module?

I am thinking this is not likely to work because my interface is SDIO and this appears to be written for plain SPI.

I also tried the DataLogger project and had partial success. New files got created but they had gibberish names. One even had the semblance of real data intermixed again with garbage.

So what am I doing wrong? I have read the main threads on this forum concerning the T4 and SD cards. Looks like I am maybe not the only one confused and befuddled. What is the proper way to be able to log data to an SD card using a T4 and the SDIO 4 lane interface? Might someone even have a working example they might share?
 
The card data in version 2 appears to be from the CID and CSD registers. These registers are read using just the CLK and CMD signal lines. Reading actual card data on the other hand requires the DAT pin(s) so it appears you have an intermittent problem there.
 
so it appears you have an intermittent problem there.

Solder joints look all solid under a microscope. Possibly a bad SD socket. Or possibly the wires too long between T4 and SD card.

Any suggestions for max length?

Thank you for you reply.
 
Somehow the long and very articulate and amusing update I made got lost. So here is a second less illuminating try.

I cut the wires back to two inches from an embarrassingly longer set. Now things seem to work much better and the same way each time.

But I would like to ask a follow up if I might as I am confused about the various libraries used by the various sample programs.

SPI.h Interface for generic CLK/MOSI/MISO/SS by directional serial.
SD.h Appear to be an interface class for accessing the file system on an SD card.
SdFat.h Also appears to be an interface class for accessing the file system on SD cards.

Should I be making the assumption that SD.h is using the single lane SPI interface to the SD card and the SdFat can use SPI or the four lane SDIO interface?
If I wanted something like the DataLogger example but to use SDIO I would need to rewrite it using the comparable methods from SdFat.h?

Or am I all wet?
 
I am not the person to answer any questions on the Teensy libraries. I skipped those and programmed the hardware directly in Forth. So I have a fair understanding of how the SD interface works (I dislike the use of SDIO as that refers to a particular class of I/O card used over the SD bus.) but not the library code.

I have seen where the symbol BUILTIN_SDCARD should be used when initializing the SD library. A Google search should reveal details.
 
Status
Not open for further replies.
Back
Top