Migrating SD Card project from regular Arduino to Teensy

Status
Not open for further replies.

mockba

Member
Hi All,

I have a project called "RunCPM" (https://github.com/MockbaTheBorg/RunCPM) which emulates a Z80 CP/M computer on an Arduino DUE (with SD Card shield).
Right now the code lines which refer to the SD card on this project are:

#include <SPI.h>
#include <SD.h>
#define SDcs 4 // Pin for the SD chip select signal
pinMode(SDcs, OUTPUT);
digitalWrite(SDcs, LOW);
if (SD.begin(SDcs)) {

I was expecting to migrate this project to the Teensy 3.5 (or 3.6, I have both) by just changing the SDcs pin definition, however this doesn't seem to be the case.
Right now I have Arduino 1.6.11 and the latest 1.31 Teensyduino.
When I build the code I see a message saying:

Multiple libraries were found for "SD.h"
Used: C:\Arduino\hardware\teensy\avr\libraries\SD
Not used: C:\Arduino\libraries\SD

So I am guessing the right SD library is being used.
I have tried changing from 4 to BUILTIN_SDCARD among other things I saw online, but I am unable to initialize the SD card.
Am I missing something?
Changing from this to that SD library is not an option, and I don't see a reason to do it, as the project works fine with the default SD library (on the DUE).
Is there a "step-by-step" tutorial on how to migrate SD access from regular Arduino to the Teensy 3.(5/6)? I couldn't find a clear solution on Google, so I figured I would ask it here.

Thanks in advance for any help.

Thanks,
Marcelo "Mockba" Dantas.
 
I have tried as well the examples contained on the Teensy's SD library folder, changing the CS from 4 to BUILTIN_SDCARD, and they won't work either.
Same thing happens, they can't detect the SD card.
I have tested with many different SD cards and on all of my 4 Teensy (2x3.5 and 2x3.6), same results.
It can't be hardware issue, I must be missing something somewhere.
Tried googling for a clear example on how to use the native (Teensy) SD library, to no avail.

Any help is really appreciated at this point.

Thanks,
Marcelo.
 
With T-3.5 or 3.6 there is this post about new SD support on those devices that shows the usage: microSD-slot-on-teensy-3-6

To migrate from DUE and use the PJRC this change is the minimum that will be needed - and have to use the SD library included with Teensy as the hardware interface is a faster 4 bit hardware interface - not the old style 1 bit SPI.

<edit> : Tried Examples / SD / listfiles and it works with this change :: if (!SD.begin(BUILTIN_SDCARD)) {
> Also works :: Examples / SD / ReadWrite
 
Last edited:
sanity check: are you inserting a microSD card into the carrier slot ON the T3.5/3.6?

Oh yes I was... no issue there.
I think I've found what the issue is.

The cards I had in my desk were all type SD1. So I tried all the different cards and none worked.
Then I went upstairs and grabbed a card from my camera, that is an SDHC, and it works. Also grabbed a SD2 from the wife's camera and it works as well.
However no SD1 I was able to find around the house works. (and of course all the cards I have available on my lab are SD1)
Is there any special thing to do when using SD1 cards? They all work fine on the Arduino DUE I have.
Maybe some speed related configuration or something like that?

Thanks,
Marcelo.

Edit: Tried the SD(type 1) card on a Teensy 3.2, using Adafruit's micro SD adapter and it reads fine (using SPI). So it is only Teensy 3.5/3.6 who is complaining about these cards.
 
Last edited:
I don't have any SD1 microSD cards, so I can't test. I couldn't find a reference that said SD1 does not support 4-bit SDIO, but it's possible those cards won't work with the builtin microSD on the T3.5/3.6. If you want to experiment, you could try the SdFat library for T3.5/3.6 or the uSDFS library.
https://github.com/greiman/SdFat-beta
https://github.com/WMXZ-EU/uSDFS

of course, you could use an external SD adapater with the T3.5/3.6 as you did with your T3.2 and use the same SPI pins as on the T3.2.
 
Last edited:
AFAIK, SDv1 cards use byte addresses for read/write and SDv2 cards use logical blocks (512 byte chunks) for addressing the SD card.
both, Bill and my FS interfaces are checking this. However, I never tested a SDv1 (I do not have one), so if uSDFS has some problems, please report on forum.
 
AFAIK, SDv1 cards use byte addresses for read/write and SDv2 cards use logical blocks (512 byte chunks) for addressing the SD card.
both, Bill and my FS interfaces are checking this. However, I never tested a SDv1 (I do not have one), so if uSDFS has some problems, please report on forum.

Thanks everyone for the answers. Unfortunately I can't replace the libraries as they work fine on Arduinos. So I will just leave as is for now and refrain from using SD1 cards.

Thanks!
 
Perhaps the issue is lack of support for 4 bit SDIO mode?

Any chance you could send me one of those cards for testing? I'd be happy to send you a newer SDHC card that works.
 
I have managed to reproduce the problem.

I found three cards which are SDv1. They are 1G, 512M and 128M size. The 1G reads find in both SPI and SDIO. The two smaller cards read only on SPI.

Hope to have a fix soon....
 
Here's a fix. It makes my two small SD1 cards work. Please let me know how it works with your cards?

This file goes into hardware/teensy/avr/libraries/SD/utility.
 

Attachments

  • KinetisSDHC.c
    29.6 KB · Views: 407
@mockba - Any chance you could give this fix a try with your SDv1 cards? I tested here, but I only have 2 cards that old. Both work with the fix, but it'd be nice to verify against more cards if you can give this a try.
 
@mockba - Any chance you could give this fix a try with your SDv1 cards? I tested here, but I only have 2 cards that old. Both work with the fix, but it'd be nice to verify against more cards if you can give this a try.

Sure ... I am working with a customer right now, but as soon as I finish I will run a test with my cards (256M ones I have).

Update: It works. The cards are KingMax (?!?) 256M. They are working fine after the patch. They are visibly slower than the SD2 ones, but this can be the card itself. It is emulating an 8bit CP/M machine anyways, so who cares about speed... :)

Thanks,
Marcelo.
 
Last edited:
Status
Not open for further replies.
Back
Top