Go Down

Topic: uint64_t data type implementation (Read 2047 times) previous topic - next topic

BTY the other thread or topic was by Criomod, titled CRC-CCITT Not returning valid...

tuxduino

What is the ouput of that sketch ?

Also, could you provide the link to crc16.h you're using ? I'd like to try it out. Thank you ! :)

Hi Tuxduino,
The output is:

0 : 0 : 80 : 8408
8408 : 1 : 0 : 8CCC
8CCC : 2 : 0 : CEC
CEC : 3 : 0 : 2D6E
2D6E : 4 : 3 : B8CE
B8CE : 5 : 9F : 43B4
43B4 : 6 : 0 : F3EC
F3EC : 7 : 1 : 3C18
3C18

and the link is : http://www.nongnu.org/avr-libc/user-manual/group__util__crc.html

ATB Dan

tuxduino

Thanks for the link. I'll try a test sketch ASAP. Meanwhile...

Quote
but I can't seem to get it to work here is my sketch and some real tag data


what is the problem with the output you posted ? Is the CRC wrong ?

tuxduino

Here's my test sketch:

Code: [Select]

// crc16 calculation test
//
// Instruction:
// - upload
// - open serial monitor at 115200
// - set line termination cr lf
// - send a string
// - read the crc16 value
// - check the result here:
// http://www.lammertbies.nl/comm/info/crc-calculation.html

#include <util/crc16.h>

const char CR = 13;
const char LF = 10;
const byte BUFSIZE = 100;
char buffer[BUFSIZE];
byte bufCnt = 0;

void processBuffer(const char* buf) {
   int len = strlen(buf);
   
   if (len == 0) {
       Serial.println("Buffer is empty.");
   }
   
   uint16_t crc = 0;
   for (int i = 0; i < len; i++) {
       crc = _crc16_update(crc, buf[i]);
   }
   
   Serial.print("String=");
   Serial.println(buffer);
   Serial.print("crc16=");
   Serial.println(crc, HEX);
}

void processChar(char ch) {
   if (ch == CR || ch == LF) {
       if (bufCnt > 0) {
           buffer[bufCnt] = 0;
           processBuffer(buffer);
           bufCnt = 0;
       }
   }
   else {
       if (bufCnt < BUFSIZE - 1) {
           buffer[bufCnt] = ch;
           bufCnt++;
       }
   }
}

void setup() {
   Serial.begin(115200);
}

void loop() {
   if (Serial.available()) {
       processChar(Serial.read());
   }
}

Coding Badly


Code: [Select]
//byte FDXBData[] = {0x35, 0x29, 0x71, 0x00, 0x03, 0x8f, 0x00, 0x01}; // reversed ie littlend lsb first, id# 000009344172, country code 967 crc should be 0x4FEB
byte FDXBData[] = {0x80, 0x00, 0x00, 0x00, 0x03, 0x9f, 0x00, 0x01};  // reversed  crc should be 0x2E44, id# 000000000001, country code 999


...where did you get the examples you used in your sketch?


From the Wikipedia article it looks like the start bits are either not included or are not the correct values.


The Priority 1 Design description is difficult to trust because the diagram directly contradicts the written description.


Hi Tuxduino,

You been a great help, the online calculator gives an mirror image of the required crc for the CCITT XMODEM, thus giving 0x2274 mirrored 0x2E44 and  0xD7F2 mirrored 0x4FEB  for the two data streams.
I can see your sketch is almost work as it sends ASCII codes. Very interesting.

Thanks for your help, I shall work further on it tomorrow.

ATB Dan.

Hi Coding Badly,

Both data streams are valid, one is from a real tag decoded manually using a DSO  :smiley-eek-blue: and the other is a test tag (country code 999)  taken from an Atmel data sheet http://www.atmel.com/Images/doc9114.pdf. the header, control and other bits have all been removed.


ATB Dan.

Coding Badly


Perfect match...

Code: [Select]
#include <util/crc16.h>

byte FDXBData[] = { 0x80, 0x00, 0x00, 0x00, 0x03, 0x9f, 0x00, 0x01 };

void setup( void )
{
  Serial.begin( 115200 );
 
  uint16_t crc;
 
  crc = 0x0000;

  for ( int i = 0; i < sizeof(FDXBData); ++i )
  {
    crc = _crc_xmodem_update( crc, FDXBData[i] );
  }
  Serial.println( crc, HEX );

  // 2274
}

void loop( void )
{
}

Go Up