Pages: 1 [2]   Go Down
Author Topic: uint64_t data type implementation  (Read 1282 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ! smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's my test sketch:

Code:
// 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());
    }
}
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Code:
//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.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Perfect match...

Code:
#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 )
{
}
Logged

Pages: 1 [2]   Go Up
Jump to: