SD Karte - CRC Berechnung

OP #600665
HI Leute!

Ich habe ein bisschen Probleme mit der Checksummenberechnung der 
SD/MMC-Speicherkarten.

Das Generatorpolynom ist: G(x) = x^7 + x^3 + 1
M(x) ist die zu übertragende Nachricht.

CRC = Rest( ( M(x) * x^7) / G(x) )

So steht es im HITACHI-Datenblatt.

Sendet man nun CMD0 an die Speicherkarte hängt man als CRC 1001010 an. 
Warum?

Eigentlich müsste es doch 0 sein, oder?

Und kann es sein, dass das Generatorpolynom falsch ist? Müsste es 
eigentlich nicht G(x) = x^6 + x^3 + x^2 + 1 heißen?

Gruß
Konstantin
Gast #600980
Das geht alles auch ohne CRC-Berechnung. Wenn du es doch mit machen 
möchtest, schaun noch ein weiters mal ins Datenblatt, oder nimm dir ein 
anderes Datenblatt zur Hand, oder schau dir die 100000 von Beispielen im 
Internet an.
Gast #600983
Noch was konstruktives:
1. Schau dir CMD59 an.
2. G(x) = x^7 + x^3 + 1 ist richtig.
3. Da CMD0 eine Konstante ist, kannst du als CRC auch eine Konstante 
nehmen, also brauchst du die CRC nicht berechnen.
OP #601457
OK Danke.

Folgendes noch. Im Datenblatt steht:

M(x) = (first bit) * x^n + (second bit) * x^(n-1) + ... + (last bit) * 
x^0

müsste es nicht so heißen?:

M(x) = (last bit) * x^n + ... + (second bit) * x^1 + (first bit) * x^0

Gruß
Konstantin
#601795
hier mal den Code den ich benutze
1
#ifdef MMC_CALC_CRC7
2
uint8_t mmcCRC7(uint8_t crc, uint8_t data) {
3

4
    crc ^= data;
5
    unsigned char poly = 0x89;
6
    for (unsigned char i = 8; i > 0; i--) {
7
      if ((crc & 0x80) != 0) crc ^= poly;
8
      crc <<= 1;
9
    }
10
    return(crc);
11
}
12
#endif

und hier in der Anwendung beim Senden eines Kommandos
1
uint8_t mmcCommandParam(uint8_t command, uint32_t address, uint16_t expected) {
2

3
    mmcDisable();
4
    mmcSend(data);
5

6
    uint8_t crc = 0;
7
#ifdef MMC_CALC_CRC7
8
    crc = mmcCRC7(crc, command);
9
    crc = mmcCRC7(crc, (uint8_t)(address >> 24));
10
    crc = mmcCRC7(crc, (uint8_t)(address >> 16));
11
    crc = mmcCRC7(crc, (uint8_t)(address >> 8));
12
    crc = mmcCRC7(crc, (uint8_t)(address));
13
    crc = crc | 1;
14
#else
15
    crc = 0x95;
16
#endif
17

18
    uint8_t result;
19
    uint8_t data = 0xFF;
20

21
    mmcWait();
22
    mmcEnable();
23
    for (uint8_t i = MMC_COMMAND_TRIALS; i > 0; i--) {
24
      mmcSend(command);
25
      mmcWait();
26
      mmcSend((uint8_t)(address >> 24));
27
      mmcWait();
28
      mmcSend((uint8_t)(address >> 16));
29
      mmcWait();
30
      mmcSend((uint8_t)(address >> 8));
31
      mmcWait();
32
      mmcSend((uint8_t)(address));
33
      mmcWait();
34
      mmcSend(crc);
35
      mmcWait();
36

37
      for (uint8_t j = MMC_RESPONSE_TRIALS; j > 0; j--) {
38
        mmcSend(data);
39
        mmcWait();
40
        result = mmcRead();
41
        if ((result & 0x80) == 0) break;
42
      }
43

44
      if ((result >= (uint8_t)(expected >> 8)) && (result <= (uint8_t)(expected))) break;
45

46
      mmcDisable();
47
      mmcSend(data);
48
      for (uint8_t j = MMC_COMMAND_DELAY -1; j > 0; j--) {
49
        mmcWait();
50
        mmcSend(data);
51
      }
52
      mmcWait();
53
      mmcEnable();
54
    }
55
    return(result);
56
}


Gruß Hagen

Antwort schreiben

Eine eigene Frage? Dieser Thread ist über 19 Jahre alt. Stell sie in einem eigenen Thread – dort lesen mehr Leute mit, und sie wird öfter und schneller beantwortet.

Neuen Thread starten

Eine Lösung, Ergänzung oder Rückmeldung zu diesem Thread? Dann antworte hier.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.