[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] MMC, CRC16, CRC7, CSD, CID
From: |
Torsten Mohr |
Subject: |
[avr-gcc-list] MMC, CRC16, CRC7, CSD, CID |
Date: |
Tue, 29 Apr 2003 10:39:41 +0200 |
User-agent: |
KMail/1.4.3 |
Hi,
at the moment i try to acess a MMC (MultiMediaCard) via
my PCs parallel port. When this works, i want to port
it to an AVR.
The communication works as i expect it, but i have problems
with some data. Here's the log of a communication with
the card. The CRC7 is calculated with the algorithm below
and at least fits for CMD0.
All numbers are in HEX:
cmd0 40 00 00 00 00 95
init 01
cmd1 41 00 00 00 00 F9
r1 01
cmd1 41 00 00 00 00 F9
r1 00
cmd9 49 00 00 00 00 AF
r1 00
data token FE
CSD 8C 0E 01 2A 0F F9 81 E9 F6 DA 01 E1 8A 40 00 2B
CRC16 7C 17
CRC7 15
CRC7 calculated is 05
cmd10 4A 00 00 00 00 1B
r1 00
data token FE
CID 06 00 00 36 34 4D 20 20 20 01 18 3B 29 2F 95 09
^^^^^^^^^^^^^^^^^
CRC16 FD AB
CRC7 04
CRC7 calculated is 28
In the CID there's a string '64M ' at index 3 which makes
sense for this 64meg card. That's why i think the communication
works.
CSD and CID are followed by a CRC16. The calculated
CRC16 doesn't fit to the CRC16 that is sent by the
card. Can you tell my why?
I calculate the CRC16 over 16 bytes CSD/CID, not over
the "data token".
Within the 16 Bytes CSD/CID there's a CRC7 in the last
byte, aligned to the MSB (7:1). Bit 0 is ALWAYS 1
according to the spec.
This CRC7 is calculated with the same algorithm that
works for commands, i think it works ok.
But i get a different result (mentioned in the log above).
CRC16:
crc = 0;
for(i = 0; i < bits; i++) {
ix = i / 8;
mask = 1 << (7-(i & 7));
xor = (crc & 0x8000) ^ (in[ix] & mask) ? 1 : 0;
crc <<= 1;
if(xor != 0) {
crc ^= 0x1021;
}
crc &= 0xffff;
printf("i %4i in 0x%02X ix %2i mask %3i crc 0x%04X xor 0x%04X\n",
i, in[ix], ix, mask, crc, xor);
}
CRC7:
crc = 0;
for(i = 0; i < bits; i++) {
ix = i / 8;
mask = 1 << (7-(i & 7));
xor = (crc & 0x40) ^ (in[ix] & mask) ? 1 : 0;
crc <<= 1;
if(xor != 0) {
crc ^= 0x9;
}
crc &= 0x7f;
printf("i %2i ix %i mask %3i crc 0x%02X xor 0x%02X res 0x%02X\n",
i, ix, mask, crc, xor, crc*2+1);
}
The data in the CSD tell me that CSD_STRUCTURE is 2.
In my product manual rev 5.1 from SanDisk there's only
a description of CSD_STRUCTURE 1.
Do you have a better documentation?
Best regards,
Torsten.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-gcc-list] MMC, CRC16, CRC7, CSD, CID,
Torsten Mohr <=