crc16 help


Closed Thread
Results 1 to 5 of 5

Thread: crc16 help

  1. #1
    beto's Avatar
    beto Guest

    Default crc16 help

    Dear Group!

    I have a device I'm trying to connect to, not very successfully... I
    need to compute a 16bit CRC and would greatly appreciate some help. I
    have an example written in C, and would like some help translating it to
    PBP. This is the only information I have on the CRC. Any help would be
    appreciated


    Thanks for any help.

    /************************************************** *********************
    ********
    * crc16
    *
    * DESCRIPTION:
    * This function computes a 16 bit CRC value for an array of bytes as
    specified
    * . The value that is returned by this
    * function needs to be inverted before it gets placed into the packet.
    The CRC
    * goes at the end of the packet, low byte first. For example:
    *
    * crc = ~crc16(0xFFFF, msgbuf, length);
    *
    *
    * INPUTS:
    * crc - the value to start computing the CRC with. This allows for
    chaining
    * together of CRC values computed for multiple arrays of data. The
    * initial value should be FFFFh (#defined as CRC_INIT).
    * ptr - the pointer to the array of bytes to compute the CRC for
    * length - the length of the data array
    *
    * OUTPUTS:
    * returns - the computed 16 bit crc value ****/
    #define unit16_t unsigned short
    #define unit8_t unsigned char

    uint16_t crc16(uint16_t crc, uint8_t *ptr, int length)
    {
    auto uint16_t i;
    while(length--)
    {
    crc = crc ^ (uint16_t) *ptr++;
    for(i=0;i<8;i++)
    {
    if(crc & 0x0001)
    crc = (crc >> 1) ^ 0x8408;
    else
    crc >>= 1;
    }
    }
    return crc;
    }

    And this is my ripped code in pbp:

    for j = 0 to lenght
    crc=crc^(send_data[j]*$ffff)
    for i=0 to 7
    if (crc & $0001) then
    crc=(crc>>1)^$8408
    else
    crc=crc>>1
    endif
    next i
    next j
    return

    but doesn't work

  2. #2
    Salutatous's Avatar
    Salutatous Guest


    Did you find this post helpful? Yes | No

  3. #3
    beto's Avatar
    beto Guest


    Did you find this post helpful? Yes | No

    Default

    your link has lot of info (more to confuse me), I found a lot of info and ways to do CRC, Witch is correct?
    CRC-16 0xBB3D
    CRC-16 (Sick) 0x56A6
    CRC-CCITT (0x0000) 0x31C3
    CRC-CCITT (0xFFFF) 0x29B1
    CRC-CCITT (0x1D0F) 0xE5CC
    CRC-DNP 0x82EA
    CRC-32 0xCBF43926
    these are CRC results from the SAME string "123456789" look at:
    http://www.lammertbies.nl/comm/info/...lculation.html

  4. #4
    Salutatous's Avatar
    Salutatous Guest


    Did you find this post helpful? Yes | No

    Default Crc16

    i use this in a modbus network and its work, try differents if you have pb!
    good luck
    ..................
    GoSub Calcul_CRC16
    BufTx[Nbr-2]=CRC16.LowByte
    BufTx[Nbr-1]=CRC16.HighByte
    SerOut2 InOut,BR,[STR BufTx\Nbr]
    ..................
    Calcul_CRC16:
    CRC16=$FFFF
    For i=0 to Nbr-3
    CRC16=CRC16^BufTx[i]
    For j=1 to 8
    IF CRC16.Bit0=1 Then
    CRC16=$A001^(CRC16>>1)
    Else
    CRC16=CRC16>>1
    EndIF
    Next j
    Next i
    Return

  5. #5
    beto's Avatar
    beto Guest


    Did you find this post helpful? Yes | No

    Default

    Tnx Salutatous I try w/other values! because there is no more info about CRC

Similar Threads

  1. How to calculate CRC16 checksum for iButton
    By ashwini kotwal in forum General
    Replies: 13
    Last Post: - 17th March 2008, 19:48
  2. OT - CRC16 program
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd March 2006, 02:12
  3. Dallas CRC16 Routines
    By Tom Estes in forum Code Examples
    Replies: 0
    Last Post: - 16th May 2005, 15:29
  4. Crc16 Ds2406
    By IceCube in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th February 2004, 14:33
  5. Checksum / CRC8 / CRC16
    By treitmey in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2003, 14:40

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts