|
|
View previous topic :: View next topic |
Author |
Message |
Josep Robert
Joined: 27 Mar 2018 Posts: 25
|
I need CRC16-CCITT(KERMIT) not CRC16-CCITT(XMODEM) |
Posted: Wed Mar 04, 2020 3:23 am |
|
|
Hello.
I need to calculate the CRC16-CCITT(Kermit) but this routine gives me the CRC16-CCITT(XMODEM).
I don't know what to change to obtain the CRC16-CCITT(KERMIT).
I don't know to implement the following definitions:
CRC-16/XMODEM
width=16 poly=0x1021 init=0x0000 refin=false refout=false xorout=0x0000 check=0x31c3 residue=0x0000 name="CRC-16/XMODEM"
CRC-16/KERMIT
width=16 poly=0x1021 init=0x0000 refin=true refout=true xorout=0x0000 check=0x2189 residue=0x0000 name="CRC-16/KERMIT"
Could you help me?
thanks in advance.
Code: |
#include <18LF47K40.h>
#use delay(clock = 16MHZ, internal)
#FUSES WDT_SW
#FUSES WDT65536
#case
void main(void)
{
unsigned int8 data[6] = {0x05 , 0x01 , 0x00 , 0x04 , 0xFC , 0xFF}; // XMODEM=7DCC. (KERMIT = 72A6)
unsigned int16 crc;
setup_crc(16, 12, 5, 0); // Setup the CRC polynomial x^16 + x^12 + X^5 + X^0
crc_init(0x0000); // Starts the CRC accumulator out at 0
crc = crc_calc16(data, sizeof(data), 8); // Returns the calculated CRC value
delay_cycles(1); // Breakpoint
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Wed Mar 04, 2020 3:39 am |
|
|
Kermit, has the bit order in the bytes reversed before processing (and
afterwards). Also the byte order is swapped in the final result.
It's otherwise the same as XMODEM. Same seed, and same polynomial.
Bit reversal can be done efficiently with:
<https://www.ccsinfo.com/forum/viewtopic.php?t=23364>
So apply this to your data, feed this through the XMODEM calculator,
then apply this again to the result. Finally swap the pair of bytes for
the result. |
|
|
Josep Robert
Joined: 27 Mar 2018 Posts: 25
|
|
Posted: Wed Mar 04, 2020 3:55 am |
|
|
Thank you very much for your immediate help. Regards. |
|
|
Josep Robert
Joined: 27 Mar 2018 Posts: 25
|
|
Posted: Wed Mar 04, 2020 4:41 am |
|
|
With this code I get the CRC-16 / KERMIT. It works fine. Thanks again Ttelmah for your help.
Code: |
#include <18LF47K40.h>
#use delay(clock = 16MHZ, internal)
#FUSES WDT_SW
#FUSES WDT65536
#case
int8 swap_bits(int8 data);
void main(void)
{
unsigned int8 i, crcH, crcL;
unsigned int16 crc;
// unsigned int8 dataA[1] = {0x00}; // CRC-16/KERMIT = 0000 ok
// unsigned int8 dataA[4] = {0x03 , 0x01 , 0x00 , 0x05}; // CRC-16/KERMIT = BC28 ok
unsigned int8 dataA[6] = {0x05 , 0x01 , 0x00 , 0x04 , 0xFC , 0xFF}; // CRC-16/KERMIT = 72A6 ok
// unsigned int8 dataA[10] = {0x09, 0xFF , 0x00 , 0x00 , 0x07 , 0x01 , 0x7F , 0x00 , 0xFF , 0xFF}; // CRC-16/KERMIT = AEF6 ok
unsigned int8 dataAreversed[10];
for (i = 0; i < sizeof(dataA); i++)
{
dataAreversed[i] = swap_bits(dataA[i]);
}
setup_crc(16, 12, 5, 0); // Setup the CRC polynomial x^16 + x^12 + X^5 + X^0
crc_init(0x0000); // Starts the CRC accumulator out at 0
crc = crc_calc16(dataAreversed, sizeof(dataA), 8); // Returns the calculated CRC value
crcH = swap_bits(make8(crc, 1));
crcL = swap_bits(make8(crc, 0));
crc = swap_bits(make8(crc, 1)) * 256 + swap_bits(make8(crc, 0));
delay_cycles(1); // Breakpoint
}
int8 swap_bits(int8 data)
{
int8 result = 0;
if(bit_test(data, 0)) bit_set(result, 7);
if(bit_test(data, 1)) bit_set(result, 6);
if(bit_test(data, 2)) bit_set(result, 5);
if(bit_test(data, 3)) bit_set(result, 4);
if(bit_test(data, 4)) bit_set(result, 3);
if(bit_test(data, 5)) bit_set(result, 2);
if(bit_test(data, 6)) bit_set(result, 1);
if(bit_test(data, 7)) bit_set(result, 0);
return result;
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Wed Mar 04, 2020 5:33 am |
|
|
Well done. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed Mar 04, 2020 6:04 am |
|
|
WOW, this is a perfect example of how this fourum can work !!
In about an hour , a challenging quetion is asked, a detailed response, and then working code posted by the original poster.
NICE !!!
sad thing is I remember when xmodem came out...... |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 554 Location: Des Moines, Iowa, USA
|
|
Posted: Thu Mar 12, 2020 9:13 am |
|
|
temtronic wrote: | sad thing is I remember when xmodem came out...... |
Then we both probably remember when XMODEM didn't have CRC (and just used a checksum) ;-) _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Thu Mar 12, 2020 10:29 am |
|
|
Problem is I remember using this with acoustic coupled modems where
the inductors used for the tone filters were the size of oranges,... |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 554 Location: Des Moines, Iowa, USA
|
|
Posted: Thu Mar 12, 2020 11:25 am |
|
|
Ttelmah wrote: | Problem is I remember using this with acoustic coupled modems where
the inductors used for the tone filters were the size of oranges,... |
Well, my first modem was a borrowed acoustic coupler, but it was a RadiShack model so probably much newer. I think you have me beat! _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Thu Mar 12, 2020 12:35 pm |
|
|
I remember the Radio Shack one. A lot later unit (mid 1980's).
Xmodem was late 1970's. Before this is was mainly all 'own coding'
on error testing. Usually custom for the company involved.
Showing our age rapidly.... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|