From: John Devereux on 1 Feb 2007 17:59 Jonathan Kirwan <jkirwan(a)easystreet.com> writes: > On Thu, 01 Feb 2007 21:06:53 +0100, janka vietzen <janvi(a)t-online.de> > wrote: > >>for the moment I struggle with the modbus protocol checksum what seems to >>use a quite odd 16 bit CRC polynom 0xA001. I have no idea if my ATmega >>assembly code works correct becouse its responsible for both directions >>generation and test same time and for the moment I do not have further >>modbus certificated devices. >> >>Is there any CRC calculator known what allows to comapare reference values? > > Isn't there sample code for calculating modbus CRCs included in the > documentation on modbus? I seem to recall seeing it near the end of > one particular manual. I'm sure I saw that too. (checks...) Yes, it's in the "Modbus over serial line specification and implementation guide V1.0". I downloaded it from the modbus web site. -- John Devereux
From: Arlet on 2 Feb 2007 02:06 On Feb 1, 9:06 pm, janka vietzen <j...(a)t-online.de> wrote: > for the moment I struggle with the modbus protocol checksum what seems to > use a quite odd 16 bit CRC polynom 0xA001. I have no idea if my ATmega > assembly code works correct becouse its responsible for both directions > generation and test same time and for the moment I do not have further > modbus certificated devices. > > Is there any CRC calculator known what allows to comapare reference values? Here's my modbus CRC code for AVR. It calculates CRC over data in 'rx_buf' with length in r24. The result has first CRC byte in r25, second CRC byte in r24 crc_update: ldi r31, hi8(rx_buf)// ldi r30, lo8(rx_buf)// ldi r26, 0xff // crc_high ldi r27, 0xff // crc_low ldi r18, 0xa0 // xor_high ldi r19, 0x01 // xor_low crc_byte: ld r20, Z+ // get next data byte eor r27, r20 // crc ^= data ldi r20, 8 // 8 bits crc_bit: lsr r26 // ror r27 // brcc crc_no_xor // eor r26, r18 // crc ^= 0xa001 eor r27, r19 // crc_no_xor: dec r20 // brne crc_bit // dec r24 // brne crc_byte // movw r24, r26 // r25:r24 = CRC16 A table based solution will be faster, but this worked fine for me, and I didn't have room for a table.
From: janka vietzen on 2 Feb 2007 08:06 Arlet wrote: many thanx, i am going to test your code. here is my first try with atMega ;** R0 tempory use ;** R16 counts Bits of a Byte ;** R17 counts Bytes of txbuf ;** R18:R19 contains polynom ;** R20:R21 CRC data ;** R30:R31 Z Register points to txbuf crcgen: ldi r17,low(txend-txbuf+1) ;r16 rxbuf length ldi zl,low(txbuf) ; Z points to txbuf start ldi zh,high(txbuf) ldi r18,0x01 ldi r19,0xa0 ;r18:r19 = CRC Polynom = 0xa001 ldi r20,0xff ldi r21,0xff ;r20:r21 is CRC register 1) ld r0,z+ ;get first Byte from txbuf bytlop: eor r20,r0 ;exor crc lowbyte with next data byte ldi r16,8+1 ;count 8 bits per byte bitlop: dec r16 ;one bit has been processed breq nbyte ;-> byte is complete lsl r20 ;shift 16 bit CRC Register rol r21 brcc bitlop ;-> shift continius if C=0 eor r20,r18 ;if Carry = 1 eor r21,r19 ;exor with 16 bit Polynom rjmp bitlop ;repeat for all 8 bits nbyte: ld r0,z+ ;fetch next byte from rxbuf dec r17 ;one byte has been processed brne bytlop ;-> until all Bytes processed ret ;CRC should be in R20:R21 now Assume txbuf contains the 6 byte modbus rtu message: 1,3,0,0,0,2 the crc should be 0xc40b (what I can see in a old trace record) but my code calculates 0x98e8 for crc result. Any bugs obvious?
From: David Kelly on 2 Feb 2007 14:38 janka vietzen wrote: > for the moment I struggle with the modbus protocol checksum what seems to > use a quite odd 16 bit CRC polynom 0xA001. I have no idea if my ATmega > assembly code works correct becouse its responsible for both directions > generation and test same time and for the moment I do not have further > modbus certificated devices. > > Is there any CRC calculator known what allows to comapare reference values? A year or so ago I used a Windows Modbus application downloadable from England as a reference for verifying correct Modbus operation with my AVR-gcc based product. The Modbus app I am thinking of would work for free for 5 or 10 minutes each time it was launched. Otherwise $60 or so. Couldn't write anything like it for only $60, money well spent. You need something for your Modbus design to talk to, else you don't know that it works.
From: Alexander Baranov on 2 Feb 2007 17:16 "David Kelly" <n4hhe(a)Yahoo.com> wrote in message news:12s74p1c5ea08fd(a)corp.supernews.com... > janka vietzen wrote: >> for the moment I struggle with the modbus protocol checksum what seems to >> use a quite odd 16 bit CRC polynom 0xA001. I have no idea if my ATmega >> assembly code works correct becouse its responsible for both directions >> generation and test same time and for the moment I do not have further >> modbus certificated devices. >> >> Is there any CRC calculator known what allows to comapare reference >> values? > > A year or so ago I used a Windows Modbus application downloadable from > England as a reference for verifying correct Modbus operation with my > AVR-gcc based product. The Modbus app I am thinking of would work for free > for 5 or 10 minutes each time it was launched. Otherwise $60 or so. > Couldn't write anything like it for only $60, money well spent. > > You need something for your Modbus design to talk to, else you don't know > that it works. > This one worked with Siemens power meter: int crc16_siemens9200(unsigned char *ptr, int count) { unsigned int crc; char i; crc = 0xffff; while (--count >= 0) { crc = crc ^ (unsigned int) *ptr++; i = 8; do { if (crc & 0x0001) crc = (crc >> 1) ^ 0xA001; else crc = (crc >> 1); } while(--i); } return (crc); } Alex.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: another bizarre architecture Next: 8051 to DVI interface? |