Forum: Mikrocontroller und Digitale Elektronik CRC mit dem CC1110 generieren


von Mops (Gast)


Lesenswert?

Hallo zusammen!

Ich versuche gerade, auf dem CC1110 eine CRC-16 Prüfsumme zu berechnen. 
Da der Stein dazu entsprechende Peripherie mitbringt, wollte ich die 
jetzt auch einfach mal nutzen. Kalkuliert wird hier mit dem Polynom X^16 
+ X^15 + X^2 + 1. Wenn ich mir nun die Werte aus dem Datenblatt nehme 
(Seite 146, Absatz 12.11.2.3), komme ich auch auf das dort angegebene 
Ergebnis 0xB4BC.

An der Gegenstelle habe ich aber keinen CC1110, dort muss ich selbst 
Hand anlegen. Doch komme ich hier nicht auf das selbe Ergebnis, hier 
kommt immer 0x2521 heraus. Ich habe auch verschiedenste Lösungen 
probiert, die ich hier im Forum gefunden habe. Das Ergebnis ist aber 
immer 0x2521, nie 0xB4BC.

Was in aller Welt mache ich falsch?

Hier noch das Datenblatt zum Nachschlagen:
http://www.ti.com/lit/ds/symlink/cc1110f32.pdf

Und noch einer meiner Versuche:
1
void crc16(WORD* pCrc, const BYTE* pFrame, WORD wLen)
2
{
3
    WORD crc = *pCrc;
4
5
    while(wLen--)
6
    {
7
        crc ^= *pFrame++;
8
        for(unsigned j = 0; j < 8; ++j)
9
        {
10
            if(crc & 0x0001)
11
            {
12
                crc = static_cast<WORD>((crc >> 1) ^ 0xA001);
13
            }
14
            else
15
            {
16
                crc >>= 1;
17
            }
18
        }
19
    }
20
21
    *pCrc = crc;
22
}
23
.
24
.
25
.
26
static const BYTE data[] = { 0x03, 0x41, 0x42, 0x43 };
27
WORD crc = 0xFFFF;
28
crc16(&crc, data, 4);
29
// Hier crc = 0x2521
von Tiramisu (Gast)


Lesenswert?

./pycrc.py --check-hexstring=03414243 --reflect-in=False --xor-in=0xffff 
--poly=0x8005 --width=16 --reflect-out=False --xor-out=0
0xb4bc

GOTCHA! [ Reverse-Bits(0xA001)=0x8005 ]

 ./pycrc.py --reflect-in=False --xor-in=0xffff --poly=0x8005 --width=16 
--reflect-out=False --xor-out=0 --generate c --algorithm=table-driven 
--table-idx-width 4

/**
 * \file stdout
 * Functions and types for CRC checks.
 *
 * Generated on Thu Oct 20 20:13:33 2011,
 * by pycrc v0.7.6, http://www.tty1.net/pycrc/
 * using the configuration:
 *    Width        = 16
 *    Poly         = 0x8005
 *    XorIn        = 0xffff
 *    ReflectIn    = False
 *    XorOut       = 0x0000
 *    ReflectOut   = False
 *    Algorithm    = table-driven
 ************************************************************************ 
*****/
#include "stdout.h"
#include <stdint.h>
#include <stdlib.h>

/**
 * Static table used for the table_driven implementation.
 ************************************************************************ 
*****/
static const crc_t crc_table[16] = {
    0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
    0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022
};



/**
 * Update the crc value with new data.
 *
 * \param crc      The current crc value.
 * \param data     Pointer to a buffer of \a data_len bytes.
 * \param data_len Number of bytes in the \a data buffer.
 * \return         The updated crc value.
 ************************************************************************ 
*****/
crc_t crc_update(crc_t crc, const unsigned char *data, size_t data_len)
{
    unsigned int tbl_idx;

    while (data_len--) {
        tbl_idx = (crc >> 12) ^ (*data >> 4);
        crc = crc_table[tbl_idx & 0x0f] ^ (crc << 4);
        tbl_idx = (crc >> 12) ^ (*data >> 0);
        crc = crc_table[tbl_idx & 0x0f] ^ (crc << 4);

        data++;
    }
    return crc & 0xffff;
}
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.