![]() ![]() |
I am trying to communicate to a serial device that has a data string with a calculated CRC. I am able to parse all useable data but can not seem to calculate the CRC for verification. It is an CRC-CCITT reverse algorithm, 8 bit accumulator. It uses an odd polynomial and start seed. I have looked at a Modbus example of CRC but can't seem to see how to make it work. Has anyone seen any generic crc samples in RSlogix5000? Any help would be appreciated.
![]() ![]() |
I am not sure what you are trying to do exactly, however I would suggest that you write the code using structured text. There are plenty of examples for vb/vba on crc, I have written various modbus functions with vba.
Regards
Kevin
Regards
Kevin
![]() ![]() |
Thanks Kevin,
Unfortunately, I have a requirement to use ladder logic. What I am trying to do is calculate the CRC code at the end of a data string I receive.
Unfortunately, I have a requirement to use ladder logic. What I am trying to do is calculate the CRC code at the end of a data string I receive.
![]() ![]() |
There's a CRC calculator in excel that you may find helpful to understand how the calculation works. see www.simplymodbus.ca/crc.xls
![]() ![]() |
There is a sample program installed with RSLogix 5000 for Modbus RTU over the serial port; it includes a CRC calculation subroutine.
I haven't tried to re-purpose it but I have a project coming up that does exactly that. I'm going to implement a protocol that includes a CRC (but isn't Modbus) using the 1734-232ASC module.
I haven't tried to re-purpose it but I have a project coming up that does exactly that. I'm going to implement a protocol that includes a CRC (but isn't Modbus) using the 1734-232ASC module.
![]() ![]() |
Don't think in terms of CRC-CCITT etc - you'll find it HIGHLY misused and will lead you into frustration. I have seen the Modbus CRC described about a dozen different ways, often wrong. I have seen people publish incorrect polynomials, claiming they are for Modbus.
Just find an exact example known to work and use it. For example, the Modbus/RTU 'serial' doc at modbus.org includes an 8-bit example:
http://modbus-ida.org/docs/PI_MBUS_300.pdf
If you find this routine not working, then add parenthesis everywhere because compiler differences in precedence is the primary source of failure I've seen. Since the RSLogix is 32-bit, you may also been to do explicit masking down to 16-bit in places.
FYI - the CRC for Rockwell DF1 is exactly the same as Modbus/RTU, accept for Modbus/RTU starts with a CRC seed of 0xFFFF and DF1 starts with 0x0000. So I do assume the RSLogix systems do have a CRC routine, which if you can pre-seed can be used for both DF1 and Modbus/RTU.
Just find an exact example known to work and use it. For example, the Modbus/RTU 'serial' doc at modbus.org includes an 8-bit example:
http://modbus-ida.org/docs/PI_MBUS_300.pdf
If you find this routine not working, then add parenthesis everywhere because compiler differences in precedence is the primary source of failure I've seen. Since the RSLogix is 32-bit, you may also been to do explicit masking down to 16-bit in places.
FYI - the CRC for Rockwell DF1 is exactly the same as Modbus/RTU, accept for Modbus/RTU starts with a CRC seed of 0xFFFF and DF1 starts with 0x0000. So I do assume the RSLogix systems do have a CRC routine, which if you can pre-seed can be used for both DF1 and Modbus/RTU.
![]() ![]() |
Listen to Lynn: he's an absolute expert on this.
I looked at the Modbus CRC routine inside RA's ControlLogix example implementation of Modbus on the serial port. It's not pretty, and it's not internally documented well (it was meant to be plugged in and not altered).
But if you look closely at the CRC lookup tables and C implementation in the PI_MBUS_300 document Lynn mentioned, you'll see that the variable names RA used are identical to the variable names in the document.
You can re-use the Modbus Master calculation loop and calling routine from that program to calculate a CRC in pure ladder logic.
I looked at the Modbus CRC routine inside RA's ControlLogix example implementation of Modbus on the serial port. It's not pretty, and it's not internally documented well (it was meant to be plugged in and not altered).
But if you look closely at the CRC lookup tables and C implementation in the PI_MBUS_300 document Lynn mentioned, you'll see that the variable names RA used are identical to the variable names in the document.
You can re-use the Modbus Master calculation loop and calling routine from that program to calculate a CRC in pure ladder logic.
![]() ![]() |
I modified the CRC calculation in RA's Modbus Master example to function on a string and it works correctly.
It's just in ladder logic. Ten rungs or so total.
You would need to alter the seed value (very easy, it's in the first rung) and re-calculate the CRC tables for your specific polynomial.
Send me a message via the forum if you want this example sent.
It's just in ladder logic. Ten rungs or so total.
You would need to alter the seed value (very easy, it's in the first rung) and re-calculate the CRC tables for your specific polynomial.
Send me a message via the forum if you want this example sent.
![]() ![]() |
Hi Eddie,
Referring to your reply here it seems that you got the solution. I'm also struggling with this problem. Can you share it with me please how the rungs for CRC CCITT works?.. It would be very helpful.
> I modified the CRC calculation in RA's Modbus Master example to function on a string and it works correctly.
Referring to your reply here it seems that you got the solution. I'm also struggling with this problem. Can you share it with me please how the rungs for CRC CCITT works?.. It would be very helpful.
> I modified the CRC calculation in RA's Modbus Master example to function on a string and it works correctly.
![]() ![]() |
Hi ntpman,
do you manage to program the CRC16-CCITT? Could you share the program with me because I am also struggling and don't know how to program it in RSlogix5000. Appreciate your help on this matter.
do you manage to program the CRC16-CCITT? Could you share the program with me because I am also struggling and don't know how to program it in RSlogix5000. Appreciate your help on this matter.
![]() ![]() |
Hello!
I write because I am implementing a system of communication between 2 devices which conducted the program only one of them. I want my screen display for data values that sends me the other device. The other device driving a start bit, source address, destination address, 5 bits of data, 9600 baud, no parity bit and stop bit. Works with RS-485 protocol with RTU. I have not worked with these protocols, I'm looking for online information about it but nothing concrete ... Upon receiving data enable me never active PIR1,RCIF for now I have the correct UART configuration, as in the other device. I hope I can help. Here is part of my code:
I write because I am implementing a system of communication between 2 devices which conducted the program only one of them. I want my screen display for data values that sends me the other device. The other device driving a start bit, source address, destination address, 5 bits of data, 9600 baud, no parity bit and stop bit. Works with RS-485 protocol with RTU. I have not worked with these protocols, I'm looking for online information about it but nothing concrete ... Upon receiving data enable me never active PIR1,RCIF for now I have the correct UART configuration, as in the other device. I hope I can help. Here is part of my code:
RECEP
BTFSS PIE1,RCIE
GOTO Exit
BCF STATUS,RP0
BTFSS PIR1,RCIF
;finalizar comprobación de interrupción por recepción
GOTO Fin_RECEP
BTFSC RCSTA,OERR
;OERR: bit de error por desbordamiento
GOTO SAL_Overrun ;Sale de la interrupción
BTFSS RCSTA,FERR
;FERR: Bit de error enmarcado
;Subrutina chequeo de desbordamiento
GOTO RECEP_Overrun
;Recepción de datos
MOVF RCREG,W
GOTO Exit ;Recuperar el estado inicial del PIC y sale de la interrupción
RECEP_Overrun ;Recepción de datos
.
.
.
SAL_Overrun ;Sale de la interrupción
.
.
.
EXIT
retfie
;Comienza el programa
;Configuración de registros
BSF STATUS,RP0
MOVLW K_ADCON1 ;Ninguna entrada analógica
MOVWF ADCON1
MOVLW K_OPTION_REG ;PRescaler asig (1/64)
;RB0/INT, pull-up desactivado
MOVWF OPTION_REG ;Pull-up desactivado, TMR0 con PRE 2
BCF STATUS,RP0
MOVLW RECARGA_TMR0
MOVWF TMR0
MOVLW Baud_Rate_Constant ;(D'25')
MOVWF SPBRG ;Vel de comunic a 9600 baudios
BSF TXSTA,BRGH ;Altas velocidades
BCF TXSTA,SYNC
BCF TXSTA,TX9
BSF TXSTA,TXEN
BCF STATUS,RP0
BCF RCSTA,RX9
BSF RCSTA,SPEN
CLRF PIR1
CLRF PIR2
BSF STATUS,RP0
CLRF PIE1
CLRF PIE2
BCF STATUS,RP0
CLRF INTCON
BSF INTCON,T0IE
BSF INTCON,PEIE
BSF INTCON,GIE
;Habilito flag de interrup por recepción
MOVF RCREG,W
MOVF RCREG,W
BCF RCSTA,CREN
BSF RCSTA,CREN
BSF STATUS,RP0
BSF PIE1,RCIE
.
.
.
CODIGO
.
.
.
FIN
Your use of this site is subject to the terms and conditions set forth under Legal Notices and the Privacy Policy. Please read those terms and conditions carefully. Subject to the rights expressly reserved to others under Legal Notices, the content of this site and the compilation thereof is © 1999-2013 Nerds in Control, LLC. All rights reserved.
Users of this site are benefiting from open source technologies, including PHP, MySQL and Apache. Be happy.
Fortune
Maternity pay? Now every Tom, Dick and Harry will get pregnant.
-- Malcolm Smith








on 22 October, 2011 - 11:23 am
