JustusJohnston
Newbie
Hello all, I'm doing a simple noisemaker for a Lattice MachXO3 board using 16-bit digital audio samples, and after faffing around with tiny EEPROMs to store the samples, I decided to dive into micro SD. I eventually want to get to the point where an end user can just toss .WAV files onto the root of a FAT formatted micro SD (from a desktop OS), and then be able to select from those in-circuit using a character LCD or something. It's a slightly weird use case for micro SD, since I only really want to read 2 bytes at a time (one 16-bit sample).
Anyways, at the current point of prototyping, I have a lot of known factors (the circuit is ALWAYS 3.3V, the card is ALWAYS the same generic 2GB card formatted in FAT16), so I can make a number of assumptions.
I've successfully gotten to the point where I fully initiate the card (74 SCLKs -> CMD0 -> CMD8 -> ACMD41 -> CMD16) with SCLK at 400kHz until after the ACMD41 returns 0x00 R1 response, then I clock it up to 6 MHz. I've also successfully done CMD9, CMD10, and CMD58 just to be able to check the CSD, CID, and OCR registers and they all look fine too. For now, I'm setting BLOCK_LEN to 512 with CMD16 for max FAT compatibility.
However, when I finally go to issue the CMD17 to read a single block, I get a good R1 response (0x00), maybe 300-400 SCLKs later, I get the 0xFE token and...instead of data from the card, I get 0x55AA repeated 16 times, followed by what seems to be 480 bytes of random data and the CRC16. However, it's the SAME random data every time I issue the CMD17, regardless of what address I put in it. Of course I get the invalid address bit set in the R1 response if my address is not aligned to multiples of 512, but other than that, it doesn't matter if I use address 0x00000000, 0x00000200, or 0x01EA3400, it's 0x55AA 16 times followed by the same data. If I try setting the BLOCK_LEN smaller, I get the exact same data, but just less of it.
I understand 0x55AA is a common test pattern, and also significant as being the last two bytes as a signature of FAT, but I'm not aware of anywhere it's supposed to appear 16 times in a row at the beginning of a 512 byte block. There isn't any significance that I can tell to the rest of the "data". There aren't any particular patterns I can recognize, there isn't any English in it when you convert to ASCII, even after trying inverting bits, byte swapping, etc. More curiously, if I try a different micro SD card, it does the same thing, but the "junk data" is different. Also repeatable, but different than the 1st card. Still starts with 16 0x55AAs though. The 1st card is formatted FAT16 and has two .WAV files on it. The 2nd card is factory new, and had never even been plugged into anything until now.
At some point soon, I think I'm just going to try using a known software library and get this working on an Arduino, so I can look at the SPI with a logic analyzer and see what's different from my implementation, but I was curious if anyone here has come across this, or had any insight. What even is this data?!
For completeness, here is what I'm reading off the card:
Anyways, at the current point of prototyping, I have a lot of known factors (the circuit is ALWAYS 3.3V, the card is ALWAYS the same generic 2GB card formatted in FAT16), so I can make a number of assumptions.
I've successfully gotten to the point where I fully initiate the card (74 SCLKs -> CMD0 -> CMD8 -> ACMD41 -> CMD16) with SCLK at 400kHz until after the ACMD41 returns 0x00 R1 response, then I clock it up to 6 MHz. I've also successfully done CMD9, CMD10, and CMD58 just to be able to check the CSD, CID, and OCR registers and they all look fine too. For now, I'm setting BLOCK_LEN to 512 with CMD16 for max FAT compatibility.
However, when I finally go to issue the CMD17 to read a single block, I get a good R1 response (0x00), maybe 300-400 SCLKs later, I get the 0xFE token and...instead of data from the card, I get 0x55AA repeated 16 times, followed by what seems to be 480 bytes of random data and the CRC16. However, it's the SAME random data every time I issue the CMD17, regardless of what address I put in it. Of course I get the invalid address bit set in the R1 response if my address is not aligned to multiples of 512, but other than that, it doesn't matter if I use address 0x00000000, 0x00000200, or 0x01EA3400, it's 0x55AA 16 times followed by the same data. If I try setting the BLOCK_LEN smaller, I get the exact same data, but just less of it.
I understand 0x55AA is a common test pattern, and also significant as being the last two bytes as a signature of FAT, but I'm not aware of anywhere it's supposed to appear 16 times in a row at the beginning of a 512 byte block. There isn't any significance that I can tell to the rest of the "data". There aren't any particular patterns I can recognize, there isn't any English in it when you convert to ASCII, even after trying inverting bits, byte swapping, etc. More curiously, if I try a different micro SD card, it does the same thing, but the "junk data" is different. Also repeatable, but different than the 1st card. Still starts with 16 0x55AAs though. The 1st card is formatted FAT16 and has two .WAV files on it. The 2nd card is factory new, and had never even been plugged into anything until now.
At some point soon, I think I'm just going to try using a known software library and get this working on an Arduino, so I can look at the SPI with a logic analyzer and see what's different from my implementation, but I was curious if anyone here has come across this, or had any insight. What even is this data?!
For completeness, here is what I'm reading off the card:
Code:
55 aa 55 aa 55 aa 55 aa 55 aa 55 aa 55 aa 55 aa
55 aa 55 aa 55 aa 55 aa 55 aa 55 aa 55 aa 55 aa
49 e2 6a a9 21 76 51 fe d2 81 1f 60 1f 7b b1 bc
6c 10 1a 7f 39 05 f5 8b 0b c8 ef 3e 9b 41 7d d9
64 d3 78 77 59 5a d5 d5 1d 4f 82 65 b8 93 c4 fc
41 e2 e2 d0 41 d6 bc c8 9c b9 be 42 e0 2e 9b 54
dd e8 52 4e a5 ea 83 47 04 3e 98 68 9a c4 98 28
76 50 0d 58 ae a3 85 e7 3f 2d 76 a7 02 db 47 1a
fc ce 2c 54 15 98 fe 69 eb 72 ff ff a5 58 57 56
fc 72 a1 56 c9 8d 3b 54 64 5f 8d ff 71 3b fe 4d
bd 7b d1 e7 2f ff a3 ad 33 e1 4e 44 da 56 55 47
dd 30 b4 fc be 61 1c 12 a2 2c e0 da eb d7 41 3d
20 73 cd bc b0 f5 89 e2 12 3a ae ec 53 34 87 43
3b ed 0a e2 ce ab bf eb 24 15 18 7a ab d3 ed 90
23 91 4b 62 a6 dd 7g 42 a2 97 f4 ab c7 59 b8 85
a0 b0 cd 64 c6 15 a6 82 5c f1 b8 4d f1 88 91 43
b9 25 17 01 22 2c 3b 85 40 f9 ca c9 95 d3 41 4c
94 e3 e4 e2 c9 ec 1a 89 0c e2 bd 61 f2 02 0e e9
e2 be 63 e2 27 13 93 8c 4e b7 58 55 a5 c2 a3 58
d2 ea 53 b8 b1 72 94 45 15 d1 50 6a 1d 3c 71 32
e2 98 19 59 45 8f bf 1e 6e ae 1d bc da 4c 24 19
f2 f0 9c 7d bf 9a 29 d3 73 33 05 19 62 bb 54 1e
74 fe bc d4 a4 05 b2 fa 2d 99 38 76 2f a4 ad f2
51 6b 39 e2 b5 b6 40 4b 38 12 6d 65 23 16 2d 15
02 78 b5 7c 61 35 55 19 55 0e 4a 99 a3 7f d6 b4
4b 06 53 63 f1 29 a0 03 33 1c fd 7f 87 d4 c6 90
0e c2 8c 3b 9a 8b d9 fc b6 a6 e2 53 40 45 32 df
ce 77 0b 5f a0 0d 5c bf c5 0c b5 ee 39 7e c8 0d
26 e9 87 67 7a 57 a3 b1 5b 40 46 92 c6 ee 1a 6b
70 88 f0 0a 27 33 45 0n 1e 0a 64 62 cb ed 47 e3
6a 1b 7c 3a 2e c6 54 97 15 a7 80 d9 c7 7b f6 af
fd 31 7c ca 85 e3 93 9a 5d 97 3b 19 dc b9 44 be
CRC16: b3 3b
Last edited by a moderator: