PDA

View Full Version : SD issues on Teensy 3



djsz
10-27-2012, 10:19 PM
I've been enjoying my Teensy 3 and using the on-board RTC, touch pins, and have wired up LCD and OLED displays from Adafruit. However, I can't get the SD library working with the PJRC Micro SD adapter--either the library that Paul updated two beta versions ago or the new SDFat beta. The SD.begin() call always returns false whether I call with a custom CS pin as parameter or with the default CS pin (pin 10) and no parameter.

I know the SPI pins on my T3 are functional because I'm running an OLED display through these SPI pins as I write this. The SD adapter is also functional because I swapped in a Teensy 2 on the same breadboard using the same breadboard wires and holes on the SD side and that worked fine. I've even powered the SD adapter using the T3's power pins and used the T2's SPI signals (this arrangement also worked).

I have also tried using a variety of CS pins, setting the hardware SS pin(s) to outputs, and all sorts of other wiring variations. I can't find anything in the code that might obviously be tripping me up: I'm using the examples verbatim from the SD and SDFat libraries, either specifying a custom CS pin in the initialization call or using the default hardware SS pin with no parameter passed to the .begin function.

I can post photos of wiring and samples of code later, but for now I'd like to know if anyone else is having problems with SD on T3. Anyone?

Thanks!

Dave

djsz
10-27-2012, 10:22 PM
One other thing I noticed: when using other SPI devices the CLK pin, which is the same as the LED at pin 13, flashes the attached LED consistently during SPI activity. When running any of the SD examples the LED never illuminates...

JBeale
10-28-2012, 12:06 AM
I had something similar with SPI until I remembered I did not have the latest (beta 6) on one of my computers. SPI would work normally with some of my code (for one type of SPI ADC for example), but it was completely dead if I used spi.setmode or spi.setclockdivider.

pixelk
10-28-2012, 11:52 AM
With the beta6, I had no problem using SD and SDFat libraries.

As for the Led blinking with CLK activity, it's perfectly normal.

Are you sure your SD adapter is able to work with the Teensy 3.3V ?

djsz
10-28-2012, 03:52 PM
Thanks for the input, @JBeale and @pixelk. I'm using the MicroSD adapter that Paul sells through PJRC--it has a 3v voltage regulator and a buffer chip (74LCX25) to handle 5v-3v logic. I've tried powering it from the T3's Vin (using USB power) as well as the 3.3v out. There are some pads on the bottom of the board that I can jumper to, I think, bypass the regulator. I will try that and see what happens.

I do have beta 6 on multiple computers and the results are the same independent of computer. I also turned on the software SPI setting in SDFatConfig.h this morning, still with no luck. So I'm thinking I need to change some part of the hardware...

djsz
10-28-2012, 05:13 PM
So I've bridged the 3v pads to bypass the regulator, ensured I'm powering with 3.3vo, and am still having trouble. I've initialized the library with SPI_SIXTEENTH_SPEED and at one point got the volume format to report but it's certainly not reproducible. Any chance this could be a hardware fault in the SPI controller? How could I figure out that I'm not working with a defective board?

I have tried 3 MicroSD cards in this throughout my experiments.

pixelk
10-28-2012, 09:51 PM
As the adapter works with a T2, I would say it is(was) functional. I don't know if I fully understood your first post on one point, you wired the SPI correctly for the T3 after testing with the T2 ? The pins are different between the two (The adapter was made so it's stackable onto the T2 over the Mini-USB Connector, but the SPI BUS is on the other side of the board on the T3).

My working µSD reader is part of an Adafruit LCD Display, so I can't speak about the PJRC one, but Paul clearly tested it on kickstarter. I f you can rewire the regulator and make it work angain on the T2, you can't go for a faulty adapter I guess. I stupidly mixed MISO and MOSI on my first try, without any ill effect... worth a check.

djsz
10-28-2012, 10:53 PM
I'm sure the adapter hardware is functional; that's why I tested it on both my T2 and T3. My thought is that the T3 could be faulty, but that doesn't yet make sense because I can't get the SdFat library working in force software SPI mode. I have wired the adapters correctly, and differently, for the T2 and T3, and I've used both the primary and secondary hardware SPI pins on T3 (in addition to CS0 and CS1 for SS).

My wiring is this: MISO 12; MOSI 11; SCLK 13; SS 10. Vin to the adapter is from 3.3Vo on the T3, Ground to T3 ground.

#include <SdFat.h>

SdFat sd;
SdFile f;

void setup() {
Serial.begin(9600);
while (!Serial) {}
int status = int(sd.begin());
Serial.println(status);
Serial.println(int(sd.vol()->fatType()));
f.open("test.txt", O_RDWR | O_CREAT | O_AT_END);
f.println("testing 1, 2, 3.");
// close the file:
f.close();
}

void loop() {

}

I'm going to try another T3, breadboard, and wires if I can get my hands on some this week.

Thanks, everyone, for your help!

JBeale
10-28-2012, 11:52 PM
Serial.begin(9600);
while (!Serial) {}

I've never used the while (!Serial) {} construction. On Teensy 3, if your PC does not initialize the USB serial driver quickly enough, is there a chance the Teensy 3's internal USB handling times out, and then everything just locks up? Can you try it with one of the real (hardware UART) ports on T3 like Serial1.begin() ?

But if that code works consistently in your other T3 programs, then never mind.

djsz
10-28-2012, 11:59 PM
Yes, good catch. It has worked well, but I put that in having copied it from another example. The sd initialization fails even if the sketch consists only of the variable declarations, sd.begin() in its setup, and nothing in the loop. I'm stumped!

djsz
10-29-2012, 02:02 PM
Update: I momentarily had the listfiles example working with the SD library in beta 6 (but not the SdFat beta) after removing my custom library folder within my sketchbook, but that unfortunately appears to have been a non-reproducible experience. So it seems that the hardware is capable of working at some point. Still no luck getting it to work again.

Paul
10-29-2012, 07:41 PM
Maybe a poor solder connection between one of the boards and pins?

djsz
10-29-2012, 08:31 PM
Yes, definitely a possibility, and I thought about that first--but I checked each pin with an LED and it was able to light consistently, and visual inspection on those pins looks OK. Paul, you said each board is tested completely on the bed of nails, so a hardware fault inside the board (not including anything I may have done after receiving the board) is highly unlikely, right? The other odd part about this is I can't get it working via software SPI on a completely separate set of pins. And I have gotten an OLED display working flawlessly as a clock (with 500ms updates) on the same hardware SPI pins I'm using for the SD.

I've used the SD adapter in question (one of the ones you sell, Paul) on a breadboard with a circuit I tested extensively without any problems for about 3 months with a Teensy 2.0. Any solder issues would likely be on the new T3.

Is there any other way to test SPI signals to ensure signals are getting out of and into the Teensy correctly? I don't have any other SPI peripherals.

Thanks for everyone's help! I really appreciate it.

Paul
10-30-2012, 06:47 AM
I'm mystified too. This really should work.

Is this the same one where you emailed me a photo of the breadboard? That looked perfectly fine.

I was thinking I'd just hook up one on a breadboard here (even though I already tested on a point-to-point soldering vector board using pin 4 for CS). But it turns out we ran out of the SD adaptors late last week. :-(

More SD adaptors out to be available in a matter of days, likely sometime next week. If this still isn't working, I'll solder one to pins, plug it into a breadboard and try to replicate your setup as precisely as possible.

Any chance you could post the photo here?

This may be obvious, but have you tried different SD cards? I have 2 here, where both work with listfiles. When I try Bill's SdFat benchmark, one works, but the other card fails to run.

djsz
10-30-2012, 12:06 PM
Yes, that's the one. I've since tried different jumper wires, switched holes on the breadboard for the Teensy and the adapter, and have used two different SD cards consistently (one 4GB SDHC, the other 2GB...though I suppose they're both SanDisk cards...). The only thing I haven't tried is swapping out the adapter for another or the Teensy for another. The Teensy works perfectly for everything else I've tried (including the internal RTC with a soldered crystal and coin cell, touch sensing, Adafruit SPI OLED display, and the Adafruit I2C LCD backpack). I'm definitely reluctant to take to the soldering iron unless I can see somehting that might need repair, especially given the tight quarters soldering the pins.

I should note again, Paul, that I did bridge the 3V pins on the adapter to bypass the regulator and am powering it from 3.3Vo rather than Vcc when hooked up to USB.

I'm going to put the Teensy and adapter on a completely different breadboard and wire setup at the office today and see how that goes. I'll take a new photo then.

Thanks!

djsz
10-30-2012, 05:21 PM
I'm wondering if this isn't a problem with hardware SPI on my Teensy: I got the Adafruit SSD1306 library to compile (but had to comment out some lines related to TWBR) and run a display via software SPI on the T3's hardware SPI pins (11, 12, 13, and 10 for CS). But when I initialize the display via the hardware SPI command nothing works. No touching wires or anything: literally changing the initializer from using software SPI to hardware SPI. Is it possible for the hardware SPI controller to be damaged or inoperable without affecting any other behavior? Everything else I've tested is fine!

When I try to use hardware SPI for either SdFat or the SSD1306 library, I get a windows error that says "USB Device Not Recognized; one of your USB devices has malfunctioned..." and this error disappears once I stop using hardware SPI.

Paul
10-30-2012, 08:29 PM
It seems extremely unlikely that the on-chip SPI circuitry could be damaged, but the rest of the chip and normal I/O on those pins still works. Then again, Teensy 3.0 is still very new and we're still learning the minor quirks of this chip (which is also very new from Freescale), so I don't want to say "impossible".

On this next round, please give pin 4 a try for the CS signal. That's how I connected the one here.

If it still doesn't work, email me directly when the SD adaptor is back in stock and we'll work out some way to swap hardware.

djsz
10-30-2012, 08:55 PM
Yes, I tried pin 4 with no luck. I'll email you offline.

Thanks!

djsz
10-31-2012, 12:07 PM
It's fixed. As much as I thought it wasn't, this was a soldering issue. I touched up each pin on both the T3 and adapter and now everything works perfectly.

I have now learned to listen to Paul the first time... :)

Thanks, all, for your troubleshooting and assistance.