Dallas CRC8 Routines


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default Re: Dallas CRC8 Routines

    Even though I'm not a PBP developer, I've always enjoyed exchanging ideas and experiences with members here. That said, I wonder if anyone is interested in my zero overhead CRC8 method, even if it isn't a PBP example?

    In my zero overhead CRC8 method I use a portion of the 60-usec read/write 'slot' time to implement CRC8 at the bit level within the OneWire read bit routine. Here's the tail end of a read bit routine from code for an enhanced mid-range 16F device;

    Code:
    ;
    ;  bit level cumulative CRC (data bit in Carry at entry & exit)
    ;
            clrf   WREG             ;                                 |00
            rlf    WREG,W           ; save C in wreg (0x00 or 0x01)   |00
            xorwf  crc,F            ; xor b0 bits, result in 'crc'    |00
            rrf    crc,F            ; is xor result 0 (Carry = 0)?    |00
            skpnc                   ; yes, skip, else                 |00
            iorlw  0x18             ; w = x8+x5+x4+1 poly and bit 0   |00
            rrf    WREG,W           ; restore C, wreg = 0x8C or 0x00  |00
            xorwf  crc,F            ; apply the polynomial or not     |00
    ;
    ;  remainder of 60-usec read/write 'slot'
    ;
            DelayCy(46*usecs-14)    ; 46-usecs minus 14 cycles        |00
            banksel owtris          ; bank 1                          |01
            bsf     owtris,owpin    ; output hi-z '1' @ 61-usecs      |01
            banksel 0               ; bank 0                          |00
            bsf     INTCON,GIE      ; interrupts on                   |00
            return                  ; Carry = data bit                |00
    Using CRC in my DS18x20 programs is simply a matter of clearing the 'crc' variable before reading the 9 byte DS18x20 'scratchpad' or an 8 byte ROMID and verifying that the 'crc' variable equals zero afterwards. You must read all 9 'scratchpad' bytes to have a valid 'crc'. Just ignore or throw away the bytes you don't need.

    I admit I have no idea if this method could be implemented in PBP with its intrinsic OneWire commands but I suspect you gurus will find a way to use it if you think the method is worthwhile.

    Have fun. Cheerful regards, Mike (K8LH)
    Last edited by Mike, K8LH; - 8th May 2018 at 18:20.

Similar Threads

  1. Problems with CRC8 Calc in 1Wire
    By JohnB in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th March 2007, 22:01
  2. dallas ibutton to pics
    By CBUK in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 25th October 2006, 12:55
  3. Dallas 1-wire search Routine
    By jimbab in forum Code Examples
    Replies: 0
    Last Post: - 7th April 2006, 16:14
  4. Dallas Semiconductor Components Serial Numbers
    By ideaman234 in forum General
    Replies: 2
    Last Post: - 27th February 2006, 22:17
  5. Dallas CRC16 Routines
    By Tom Estes in forum Code Examples
    Replies: 0
    Last Post: - 16th May 2005, 15:29

Members who have read this thread : 3

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