Offline
Newbie
Karma: 0
Posts: 8
|
 |
« on: December 30, 2011, 05:25:32 pm » |
I have a Teensy++ 2.0 and a MicroSD card slot purchased from PJRC, but I cannot seem to get the Teensy to see the SD card slot. The test code I am using is as follows...
#include <SD.h>
void setup() { //Pause for 1 second delay(1000); //Needs to be set for the SD library to function pinMode(10, OUTPUT); //Check to make sure SD card is functioning, if not set red LED if (!SD.begin(20)) { analogWrite(16, 1023); } }
void loop() { }
I have tried multiple variations, but all I get is the red LED (pin 16). Pins 20, 21, 22 and 23 are hooked to SS, SCLK, MOSI and MISO in that order and GND and 5v are also attached to the SD card reader. When testing voltages for the pins at the SD card reader and the Teensy I get...
SS - 5 SCLK - .02 MOSI - 5 MISO - 3.3 5v - 5
Any thoughts would be greatly appreciated... thanks!
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #1 on: December 30, 2011, 05:35:15 pm » |
Monitoring the 4 pins on the Teensy through analogRead, here is what I get...
SS - 1020 SCLK - 1007 MOSI - 1020 MISO - 1023 SS - 1020 SCLK - 1012 MOSI - 1016 MISO - 1021 SS - 1021 SCLK - 1016 MOSI - 1016 MISO - 1019 SS - 1021 SCLK - 1018 MOSI - 1015 MISO - 1014 SS - 1023 SCLK - 1020 MOSI - 1016 MISO - 1013 SS - 1022 SCLK - 1021 MOSI - 1018 MISO - 1015 SS - 1020 SCLK - 1021 MOSI - 1020 MISO - 1018 SS - 1019 SCLK - 1020 MOSI - 1020 MISO - 1020 SS - 1018 SCLK - 1019 MOSI - 1021 MISO - 1 SS - 1018 SCLK - 1017 MOSI - 1020 MISO - 1 SS - 1018 SCLK - 1017 MOSI - 1019 MISO - 0 SS - 1020 SCLK - 1018 MOSI - 1018 MISO - 1022 SS - 1021 SCLK - 1019 MOSI - 1018 MISO - 1020 SS - 1022 SCLK - 1020 MOSI - 1017 MISO - 1015 SS - 0 SCLK - 1023 MOSI - 1019 MISO - 1015 SS - 1023 SCLK - 1023 MOSI - 1020 MISO - 1016 SS - 1022 SCLK - 1023 MOSI - 1022 MISO - 1019 SS - 1021 SCLK - 1022 MOSI - 1022 MISO - 1021 SS - 1020 SCLK - 1021 MOSI - 1023 MISO - 1 SS - 1018 SCLK - 1019 MOSI - 1022 MISO - 2 SS - 1019 SCLK - 1018 MOSI - 1020 MISO - 0 SS - 1021 SCLK - 1019 MOSI - 1019 MISO - 1022 SS - 1022 SCLK - 1020 MOSI - 1019 MISO - 1020 SS - 1022 SCLK - 1021 MOSI - 1018 MISO - 1016 SS - 0 SCLK - 0 MOSI - 1021 MISO - 1016 SS - 1023 SCLK - 0 MOSI - 1022 MISO - 1017 SS - 1023 SCLK - 1023 MOSI - 1022 MISO - 1018 SS - 1022 SCLK - 1022 MOSI - 1023 MISO - 1021 SS - 1021 SCLK - 1022 MOSI - 1023 MISO - 0 SS - 1020 SCLK - 1020 MOSI - 1023 MISO - 2 SS - 1019 SCLK - 1019 MOSI - 1022 MISO - 2 SS - 1020 SCLK - 1019 MOSI - 1021 MISO - 0 SS - 1021 SCLK - 1020 MOSI - 1020 MISO - 1021 SS - 1022 SCLK - 1021 MOSI - 1020 MISO - 1019 SS - 1023 SCLK - 1022 MOSI - 1019 MISO - 1016 SS - 1 SCLK - 0 MOSI - 1022 MISO - 1017 SS - 1023 SCLK - 1023 MOSI - 1022 MISO - 1018 SS - 1022 SCLK - 1023 MOSI - 1023 MISO - 1020 SS - 1021 SCLK - 1022 MOSI - 1023 MISO - 1022 SS - 1020 SCLK - 1021 MOSI - 0 MISO - 1 SS - 1019 SCLK - 1019 MOSI - 1022 MISO - 2 SS - 1020 SCLK - 1019 MOSI - 1021 MISO - 0
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35476
Seattle, WA USA
|
 |
« Reply #2 on: December 30, 2011, 07:24:55 pm » |
pinMode(10, OUTPUT); //Check to make sure SD card is functioning, if not set red LED if (!SD.begin(20)) { analogWrite(16, 1023); } Set pin 10 as output and then tell the SD card that the chip select pin is 20. Well, I don't think I'd expect that to work too well. And, apparently, it doesn't.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #3 on: December 31, 2011, 12:45:00 am » |
pinMode(10, OUTPUT); //Check to make sure SD card is functioning, if not set red LED if (!SD.begin(20)) { analogWrite(16, 1023); } Set pin 10 as output and then tell the SD card that the chip select pin is 20. Well, I don't think I'd expect that to work too well. And, apparently, it doesn't. Every post I have read on the topic says that pin 10 needs to be set as output for the SD library to work even if there is nothing on pin 10. And pin 20 is the chip select pin on a Teensy++ 2.0 according to what I have read. I have seen several examples of what claim to be working code with the same hardware that use exactly the code I am using here. My programming background is not in Arduino, so if you or anyone else have any helpful suggestions to this problem I would love to hear them.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1078
Arduino rocks
|
 |
« Reply #4 on: December 31, 2011, 12:28:19 pm » |
You don't need pinMode(10, OUTPUT); with SD.h or SdFat on any board. SD.h is a wrapper for an old version of SdFat. I wrote SdFat and it sets the correct mode for all pins that it uses. Examples on the AdaFruit site have this incorrect code and it has now become a magic incantation that appears in many sketches. At best it will do no harm but it is better to not set OUTPUT mode for pin 10. You could try running the QuickStart example in SdFat. SdFat has code for teensy++ 2 but I have not checked it lately. SdFat is here http://code.google.com/p/sdfatlib/downloads/list. If QuickStart runs on teensy++ it will give more information.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #5 on: December 31, 2011, 02:05:51 pm » |
I get the following output...
"errorCode: 0x1, errorData: 0xff"
It seems like a wiring issue but as you can see above I have checked the wiring and as far as I can tell it should be all set.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1078
Arduino rocks
|
 |
« Reply #6 on: December 31, 2011, 02:58:39 pm » |
Error code 0X1 means the SD card does not respond to the first command that SdFat sends. This is almost certainly a hardware problem.
Hope you are not connecting 5V, SCK, SS, and MOSI directly to the card. The card runs at 3.3 V and these signals are too high so you need a level shifter. You can connect MISO directly to the card.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 42
|
 |
« Reply #7 on: December 31, 2011, 03:43:01 pm » |
Hope you are not connecting 5V, SCK, SS, and MOSI directly to the card. The card runs at 3.3 V and these signals are too high so you need a level shifter. You can connect MISO directly to the card.
Only if there are no 5V devices on the SPI bus. Why doesn't anyone consider the problem of mixing 3.3V and 5V devices on the SPI bus?
|
|
|
|
« Last Edit: December 31, 2011, 07:53:01 pm by stevemarple »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #8 on: December 31, 2011, 04:09:14 pm » |
According to the product page ( http://pjrc.com/store/sd_adaptor.html), the SD board contains "a 3.3 volt regulator and 5 to 3.3 volt buffer chip protects the SD card, and allows interfacing to 5 volt processors." So yes, it is connected directly to the card. I figured it was a hardware issue, but when I measured the inputs on the SS, SCLK, MOSI and MISO on the Teensy through analogRead they all showed that they were receiving input. I have tested it with different MicroSDHC cards and tested the cards in other devices. I am somewhat at a loss here... any suggestions on other ways to check and correct potential hardware issues?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1078
Arduino rocks
|
 |
« Reply #9 on: December 31, 2011, 04:55:39 pm » |
I have used that Micro SD card adapter with a teensy successfully so it should work with the teensy++ if you have it connected correctly.
It has the proper regulator and level shifters so that is not a problem.
Measuring the voltage levels is not much of a test and analogRead is meaningless since SS is high in most of your readings so the SD is not selected.
There is nothing you can do with software tests when you get error code 0X1 since no data is received from the card. It is acting like nothing is connected to the SPI bus.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #10 on: December 31, 2011, 07:52:36 pm » |
Okay, sounds like I am pretty much out of luck then... time to pitch the whole thing and start over.
|
|
|
|
|
Logged
|
|
|
|
|
|