Weird issue with 2GB SD card
macca
Posts: 780
Hi,
I have recently purchased a couple of no-brand 2GB SD cards from eBay that shows a weird issue: the cards works perfectly on Windows, Linux and on a Canon camera, but fails to work on any other non-PC devices such as a Propeller with an SD card socket, an Arduino UNO with the Datalogger shield and a SD2IEC device (Commodore 64 disk emulator).
I have setup a quick test program with a Propeller and a SD socket. The card answers correctly to all commands, but when I try to read a block it returns garbled data, no matter what I do, the data is always garbled. I always read block 0 just to not mess with the addressing and the card is clean. Just to have an idea, it is like the data is encrypted somehow (but it is not). The same test program (or any other SD card utility) works perfectly with a 1GB Transcend card.
I tried to format the card with the SD Card Formatter utility without changes.
Searching on the 'net doesn't show any useful results, generally the cards works or fails from the beginning, not just the data block read commands.
Is there someone that has experienced a similar issue with SD cards ?
Thanks for any help.
I have recently purchased a couple of no-brand 2GB SD cards from eBay that shows a weird issue: the cards works perfectly on Windows, Linux and on a Canon camera, but fails to work on any other non-PC devices such as a Propeller with an SD card socket, an Arduino UNO with the Datalogger shield and a SD2IEC device (Commodore 64 disk emulator).
I have setup a quick test program with a Propeller and a SD socket. The card answers correctly to all commands, but when I try to read a block it returns garbled data, no matter what I do, the data is always garbled. I always read block 0 just to not mess with the addressing and the card is clean. Just to have an idea, it is like the data is encrypted somehow (but it is not). The same test program (or any other SD card utility) works perfectly with a 1GB Transcend card.
I tried to format the card with the SD Card Formatter utility without changes.
Searching on the 'net doesn't show any useful results, generally the cards works or fails from the beginning, not just the data block read commands.
Is there someone that has experienced a similar issue with SD cards ?
Thanks for any help.
Comments
These were common a number of years ago.
Why oh why oh why. For the price of a pizza I can pick up SanDisk 8GB or 16GB. Skip the pizza, not the good SD card.
Maybe these SD cards do not support SPI access. The PC and your Camera use SD mode, and the non-PC devices use the SPI mode.
Andy
If it doesn't support SPI it should not return an error or something unreadable for other commands other than CMD0 ?
All commands returns a response, I can read CSD, CID and OCR. Even the data block follows the protocol (few FF followed by the FE start token, 512 bytes data, 2 CRC).
It is about 4 months that I don't eat pizza (and I'm in Italy...). They looked good to be used for SD2IEC and MaxDuino devices and I purchased along with other memory devices (that shows other problems...). Of course now I'll stay away from these no-brand devices.
What does Windows to be spoofed ? All documents I found lists the same exact initialization sequence and AFAIK, there is nothing sent to the card that could identify the host. Maybe it is the adapter wiring that is different. All SD cards I have works, and some are very old, only these shows this problem.
No, that's not the case, the size is reported correctly (or I hope so), I have put some files on them and are all working. Of course I haven't filled them completely so maybe they are 512MB instead of 2GB, but the problem I have is that I can't read any data from them.
To give you an idea, this is a log of the commands and responses:
As you can see, all commands works correctly, but reading sector zero (which should be the MBR) returns garbled data. The same commands works correctly with all other cards I have.
If I read the card from Linux using dd the sector data is correct.
That happens with every non-PC device I have (except the camera).
Ok looks like you are sending the correct crc for each command. Only command 0 and 8 requires the correct crc so try sending crc=$87 or $95 on the other commands in case command 17 crc is wrong.
Also i see you are sending cmd 55 then 41 three times. I’ve only ever sent them once.
What program are you using to drive the SD card? Do you have any pullups on the sd card pins? Do you have a 10uF and 100nF X7R right at the sd power pins? What is the length of the tracks/wires from P1 to SD card?
However I accept that there is an academic challenge here. Why does it seem to work in a PC but not on the Prop. It seems to respond over SPI but remember that SD cards are not the same as SDHC cards. With the old SD cards the initialization is a little different plus they accessed memory in bytes rather than blocks. But I remember many years ago when 2GB were very hard to get, that I could only get these no-name ones, so I ordered 100 of them at a good price since I needed them for an older product. They seemed to work, but the customer sent them all back to me because they weren't working properly. I had to go and chase down some other 2GB card which at least had a brand name, although not a premium one.
I think they were actually crippled SDHC cards rather than the older SD, that was the main problem and perhaps that is what is happening here.
So looking through that initialization sequence it should be CMD0, CMD8, then CMD58 is recommended but ACMD41 is next etc. Not CMD55 which is an application specific command.
BTW, as long as the CMD0 and CMD8 CRCs are correct, then it doesn't matter what the crc is after that. Since CMD0 and CMD8 are fixed, just use $95 for CMD0 and $87 for CMD8 and anything else.
I have added the correct crc just in case it wasn't exactly following the specs, but also with the crc set for commands 0 and 8 only and using FF for all others doesn't make any difference. CMD17 crc looks good to me, what should it be ?
The specs say that it should be resent until the response is 00 which means the card is initialized. This is the only difference I can see from other cards, the initialization takes a lot of time, up to 20-25 seconds from the first attempt at power up. After that it takes 2-3 attempts. This is also a difference with the PC, when I put the card on the SD slot it is seen immediately, clearly there is something different either with the initialization or how the connector is wired.
I wrote a simple test program in C, also tested with SD-MMC_FATEngine in spin but it is a nightmare to debug that because it uses abort statements that make things a bit hard to track.
The circuit is very simple, tracks are a couple of cm from the Propeller, I don't have capacitors near the SD socket, I can try to add one if could be a power glitch.
I asked if someone had a similar experience, just that. I know I have thrown away some money and clearly I can't use these cards for what I want to do, but I wasn't expecting that kind of problem and now I'm just curious to see if it can be fixed. If not, ok, not a problem.
Yes, ACMD41 is 55 followed by 41, I haven't prefixed it with an A.
The CSD from my 64GB card.
More info:
You definitely need bypass and bulk caps right at the SD pins. I've seen short traces (not a few cm) from the PS fail. This is fundamental 101.
The SD card is supposed to respond with busy until it's ready. Never sent the commands more than once. I typically see delays sub 1 second until the card is ready.
As for the PC, it is likely not using SPI but the 4bit parallel mode (sort of SPI but the card is in a completely different mode after the first command(s).)
I don't send the correct crc after cmd0 and cmd8. If you do, then you are probably telling the card that crc will always be used, and if it's wrong it may fail.
@macca - what test program are you using? Some older drivers only expected SD cards for instance, and some of the newer ones only expect SDHC etc.
You can turn it on in SPI mode if you want, but we don't.
From the SD Spec:
That's interesting, I've always used bypass only. Pity I have a test board already at the manufacturer's site. Next time I'll keep in mind. Thanks.
Massimo
About the original question, scrambled data, I wonder if it could have something to do with setup time? Setup time violations can definitely scramble data. However, that doesn't seem a likely explanation either, when reading a block that is supposed to be all or mostly zeros.