完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
下面的代码是为8位CRC编写的。有人建议如何转换下面的代码为16位CRCCode修改
以上来自于百度翻译 以下为原文 The below code written for 8 bit CRC . Can someone suggest how to convert below code for 16 bit CRC unsigned int crc_fn(unsigned char *dpacket,unsigned int len) // CRC Function(Error calcualtion) { unsigned int crc = 0xffff,poly = 0xa001; unsigned int i=0; for(i=0;i crc^= dpacket; for(j=0;j<8;j++) { if(crc & 0x01) { crc >>= 1; crc ^= poly; } else crc >>= 1; } } return (crc); } Code modified unsigned short crc16(const unsigned char* data_p, unsigned char length){ unsigned char x; unsigned short crc = 0xFFFF; while (length--){ x = crc >> 8 ^ *data_p++; x ^= x>>4; crc = (crc << 8) ^ ((unsigned short)(x << 12)) ^ ((unsigned short)(x <<5)) ^ ((unsigned short)x); } return crc; } |
|
相关推荐
19个回答
|
|
上面的代码用函数代码3工作得很好。如果我想转换为函数代码1,即读取线圈寄存器,它将不工作。在函数模式中使用的上述代码i可以访问100字节的数据。函数03:如果在函数09100100031 FDDE中改变函数代码1和发送输入,则在HEX 010300 000 31841EE中给出的数据输入将导致无效的MODBUS。响应,为了实现我需要改变的函数1
以上来自于百度翻译 以下为原文 The above code work fine with FUnction code 3 . If i like to convert to function code 1 i.e read coil register it wont work. with above code used in function mode i can access 100 byte of data. function 03: data input given in Hex 010300000031841E If i change function code 1 & send input in format 010100000031fdde it will result Invalid Modbus response. In order to achieve what i need to change for function 1 |
|
|
|
嗨,这里有一个解释和示例代码的网站:HTTP://wwwSunsNe2K.DE/ToeStuls/Cucd/Cc/CuultIn CRC.HTML可以有许多方式来安排CRC计算,具有多项式值、起始值、移位方向……这是一个已知程序的目录:HTTP:/Revun.SooSurfGe.NET/CRC目录/转到16位,并找到参数的Modbus。迈西尔
以上来自于百度翻译 以下为原文 Hi, Here is a website with explanations and example code: http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html There are many ways CRC calculation may be arranged, with polynomial value, start value, shift direction ... Here is a catalog of known procedures: http://reveng.sourceforge.net/crc-catalogue/ go to 16 bits and find parameters for MODBUS. Mysil |
|
|
|
我的问题是:对于函数代码F3:Endo0103000,18411EF函数代码F1:输入010100000,FDDWEATE多项式计算是否会改变?当我检查数据表时,简单的MODBFF3使用长度=N* 2=ByTeF1的NO,使用长度=N=ByTe。使用相同的函数天气,它可能得到正确的答案,两者都被用来读取上面代码的寄存器天气是否有效?如果U可以在这里给出函数代码1的示例代码。我可以试一试。线程中有很多代码。
以上来自于百度翻译 以下为原文 My question is : For function code F3: INput 010300000031841E For function code F1: INput 010100000031fdde weather polynomial calculation will change or not? when i check datasheet simply modbus f3 uses length = N*2= no of bytes F1 uses length =N= no of bytes. using same function weather its possible to get proper answer both are used to read the register weather above code will work?? if u can give sample code here for function code 1 . i can tested out. There are lot of code involved in thread |
|
|
|
下面是代码编写和IM测试
以上来自于百度翻译 以下为原文 Below is code written & i m testing unsigned int crc_fn(unsigned char *dpacket,unsigned int len) // CRC Function(Error calcualtion) { unsigned int crc = 0xffff,poly = 0xa001; unsigned int i=0; for(i=0;i crc^= dpacket; for(j=0;j<8;j++) { if(crc & 0x01) { crc >>= 1; crc ^= poly; } else crc >>= 1; } } return (crc); } void ChecksumCal(char No_Bytes) { unsigned char highbyte,lowbyte; unsigned short crc,thi***yte,i,shift,lastbit; /* 16 bit word values */ /* compute the CRC over the first 6 chars of the message*/ crc = 0xFFFF; No_Bytes = No_Bytes -1; for(i=0;i<=No_Bytes;i++) { thi***yte = rxbuf; crc = crc^thi***yte; for(shift=1;shift<=8;shift++) { lastbit = crc&0x0001; crc = (crc>>1)&0x7fff; if(lastbit==0x0001) { crc=crc^0xa001; } } } lowbyte = (crc>>8)&0xff; highbyte = crc & 0xff; crc_m*** = highbyte; crc_l*** = lowbyte; } void Serial_Request() { unsigned int address,crc1,crc2; unsigned char length,i,j=0; // Serial_1_Send_byte(rxbuf[0]); crc2=crc_fn(&rxbuf[0],6); //crc function for received protocol from request __delay_ms(10); // Changed on 20.01.2017 if((rxbuf[6]==(unsigned char)(crc2))&&(rxbuf[7]==((unsigned char)(crc2>>8)))) { if(rxbuf[0]==device_ID) { //Serial_1_Send_byte(rxbuf[0]); if(rxbuf[1]==READ_REG) { address=(((unsigned int)(rxbuf[2]<<8))+((unsigned int)(rxbuf[3]))); if(rxbuf[5]>=1) { // changes i made for function1, if i used i get an error. length=(rxbuf[5]/8);// function code 1 address=0X01;// function code 1 // original function 3 code, if i keep below code it works fine for function 3 length=(rxbuf[5]*2);// function 3 address=(address*2);// function 3 ser_data[0]=device_ID; ser_data[1]=rxbuf[1]; ser_data[2]=length; crc_data[0]=device_ID; crc_data[1]=rxbuf[1]; crc_data[2]=length; j=3; for(i=address;i<((address+length));i++) { crc_data[j++]=ser_data[i+3]; } crc1 =crc_fn(&crc_data[0],(length+3)); //crc function for response protocol from the device Serial_1_Send_byte(ser_data[0]); Serial_1_Send_byte(rxbuf[1]); Serial_1_Send_byte(ser_data[2]); for(i=address;i<((address+length));i++) { Serial_1_Send_byte(ser_data[i+3]); } Serial_1_Send_byte((unsigned char)crc1); Serial_1_Send_byte((unsigned char)(crc1>>8)); } } __delay_ms(5); } } index=0; rec_flag = 0; } |
|
|
|
MysIL是正确的,在网络上存在过多的代码。对于Modbus RTU来说,真正需要做的只有两件事:检查CRC并生成它。如果你可以生成它,那么你可以检查它;检查它等于生成一个包含它的CRC的整个消息的CRC。如果生成的值是0,那么你就可以去了。它会更快,只有512字节。更好的是,如果你使用的是一个拥有DMA的PIC,你可以使用硬件CRC和一些MaGigAg.HTPp//www. MubtotoLo.com /MMOBUSSCRCR16.HTM。
以上来自于百度翻译 以下为原文 Mysil is correct, and there exists a plethora of code on the web for this sort of thing. For Modbus RTU, there are really only two things that you need to do: check the CRC and generate it. If you can generate it then you can check it; checking it amounts to generating a CRC for an entire message including its CRC. If the generated value is zero then you're good to go. As a small aside, use a lookup table. It will be faster and its only 512 bytes. Even better, if you're using a PIC that has DMA, you can use the hardware CRC with some massaging. http://www.modbustools.com/modbus_crc16.htm |
|
|
|
我能用Modbus RTU的任何功能使用代码吗?传递一个论点或消息。天气将在函数代码1和3上工作。对于函数1长度=(RxBuf(5)/ 8);/ /函数码1Actudio 0x01;//函数代码1WORKE,我需要将总长度除以8或不为智能I,用于函数3这里,CRC16(&CCRCYDATA(0),(长度+3));它将返回CRC值。
以上来自于百度翻译 以下为原文 can i use the code with any function of modbus RTU . Just pass an argument or message . weather it will work on function code 1 & 3 . for function1 length=(rxbuf[5]/8);// function code 1 address=0X01;// function code 1 weather i need to devide total length by 8 or not like wise i used for function 3 here, crc1 =crc_fn(&crc_data[0],(length+3)); i can calll crc1 =CRC16(&crc_data[0],(length+3)); It will return The CRC value. |
|
|
|
你正在检查整个消息。如果你收到一个消息,比如0x01,0x03.0x00,0x00,0x00,0x64,0x44,0x21,你将在所有八个字节上执行CRC函数。检查CRC时,函数代码无关。
以上来自于百度翻译 以下为原文 You're checking the whole message. If you receive a message, say 0x01,0x03,0x00,0x00,0x00,0x64,0x44,0x21, you would perform the CRC function on ALL EIGHT BYTES. Function code is irrelevant when checking the CRC. |
|
|
|
好啊。因此,我可以使用上述方法,并检查整个消息本身。如果CRC函数像非法地址返回值0x02,则响应不正确。CRC16(和CRCYDATA〔0〕,(长度+3));使用函数的方法是否正确。函数1的长度是多少。当我通过简单的方式。第五字节的长度为8。我在代码中做的是正确的吗?或者没有。
以上来自于百度翻译 以下为原文 OK. So I can use the above method and check whole message itself. If crc function returns the value 0x02 like illegal address then response are incorrect. CRC16(&crc_data[0],(length+3)); method of using function is correct or not. What will be length for function 1. When I gone through simply modus. The length for 5th byte is taken as devider value by 8. Is it correct what I m doing in code. Or not. |
|
|
|
http://www. SimyMyBux.CA/EnRONYFC1.1.HTMHTP://www. SimulyMODBUSS.CA/EnRONYFC03.HTM
以上来自于百度翻译 以下为原文 http://www.simplymodbus.ca/enron_FC01.htm http://www.simplymodbus.ca/enron_FC03.htm |
|
|
|
假设你正在接收,你收到了10个字节,然后是一个消息间延迟(Modbus SPEC)。然后,您将在整个消息上执行CRC计算,即10字节。如果你准备好发送,你很明显会建立一个响应。假设它是一个MODBUS读取(0x03)。第一个字节是地址,然后是函数代码,然后是字节数,然后是一串单词(高字节,然后是低字节)。假设一个读请求要求2个字,那么这将是3 + 2×2=7字节。然后,您将接受这7个字节的CRC,结果将是一些非零,16位整数。然后你会把这个值(CRC的高字节,然后是低字节)附加到你的消息并发送出去。至于那些链接,我没有听说过一个Modbus规格,寄存器大小是4字节。你真的想用安然Modbus作为链接吗?
以上来自于百度翻译 以下为原文 Let's suppose that you're RECEIVING, and you have received 10 bytes then an intermessage delay (modbus spec). You will then be performing that CRC calculation on the entire message, that is 10 bytes. If you're getting ready to TRANSMIT, you'll obviously build up a response. Suppose it's a modbus read (0x03). The first byte is the address, then the function code, then the number of bytes, and then a bunch of words (high byte then low byte). Suppose a read request asked for 2 words, then this would be 3 + 2 * 2 = 7 bytes. You would then take the CRC of those 7 bytes and the result would be some non-zero, 16 bit integer. You would then append this value (high byte of CRC first, then low byte) to your message and send it out. As for those links, I've not heard of a modbus spec where the register size is 4 bytes. Are you really trying to use Enron Modbus as the link says? |
|
|
|
嗨,你使用哪8位设备?PIC16F1619具有内置的硬件CRC。
以上来自于百度翻译 以下为原文 Hi, Which 8 bits device do you use ? The PIC16F1619 has a built-in hardware CRC. Regards |
|
|
|
我用的是PIC18F24K40。我知道MPLAB X IDE显示CRC功能检查。我不知道如何使用它。函数1:HTTP//www. SimulyMODBUSS.CAN/EnRONYFC01.HTM11 01 05 05 CD6BB20E1B 4E611:从地址(11个HEX=ADDRES17)01:函数代码(读取布尔变量)05:要跟随的数据字节数(37个线圈/ 8位/字节=5个字节)CD:布尔型变量1020 - 1027(1100 1101)6b:布尔变量1028~1035(0110 1011)b2:布尔变量1036~1043(1011 0010)0e:布尔变量0010 -(α)1b:函数的布尔变量α-(α):HTTP//www. SimyMyBux.CA/EnRONY-FC03.HTMMeReSeffs11.47 6C4A00083B323:从地址(3435个HEX=ADDRES17)03:函数代码(读取数字变量)04要跟随的数据字节数(1个寄存器x 4个字节每一个=4个字节)46C4A00:32位变量7021×083B的内容:CRC(循环冗余校验)。在现有的代码中,我在线程中共享,对于函数1,我需要用8。=或没有。如果我得到了用于检查函数1的CRC的示例代码,它会更有帮助。
以上来自于百度翻译 以下为原文 I am using PIC18F24K40. I know for MPlab x ide it shows CRC function check . I dont know how to use it. & there are no example code on it. For function 1:http://www.simplymodbus.ca/enron_FC01.htm 11 01 05 CD6BB20E1B 45E6 11: The Slave Address (11 hex = address17 ) 01: The Function Code (read Boolean variables) 05: The number of data bytes to follow (37 Coils / 8 bits per byte = 5 bytes) CD: Boolean variables 1020 - 1027 (1100 1101) 6B: Boolean variables 1028 - 1035 (0110 1011) B2: Boolean variables 1036 - 1043 (1011 0010) 0E: Boolean variables 1044 - 1051 (0000 1110) 1B: Boolean variables 1052 - 1056 (0001 1011) for Function 3:http://www.simplymodbus.ca/enron_FC03.htm Response 11 03 04 476C4A00 083B 3233: The Slave Address (3435 hex = address17 ) 03: The Function Code (read Numeric variables) 04 The number of data bytes to follow (1 registers x 4 bytes each = 4 bytes) 476C4A00: The contents of 32-bit variable # 7021 083B: The CRC (cyclic redundancy check). so i asked weather i need to make In existing code i shared in thread , for function 1 i need to devide by 8.= or not.If i get sample code for checking CRC for function 1 it will be more helpfull. length=(rxbuf[5]/8);// function code 1 address=0X01;// function code 1 // original function 3 code, if i keep below code it works fine for function 3 length=(rxbuf[5]*2);// function 3 address=(address*2);// function 3 |
|
|
|
嗨,Ready为Modbus使用的CRC程序编写了代码,在消息6中,你可以用“Unt1616T'和‘字节’替换:‘单词’:‘UIT88T’’MysIL。
以上来自于百度翻译 以下为原文 Hi, Ready-made code for the CRC procedure to be used for MODBUS was pointed out to you, in message #6. You may replace: 'WORD' with 'uint16_t' and: 'BYTE' with: 'uint8_t' Mysil |
|
|
|
这里我附上了我的代码集。这就是我在代码中使用函数01的方式。功能齐全。对于函数1,我用它的屏幕截图来获得错误。我还尝试了MCC生成的CRC硬件检查,但它不起作用。有人可以在CODRESIALL DATA()中使用这些CRC函数,是我在中断中调用的函数。我正在检查MasaGeS01 01、00、00、00、31、FDD、DRXBUF[0 ]=01//设备ID ALWAXRXXBUF[1 ]=01//函数CODRESXBUF[2 ]=00//更高字节的起始AdvestRSXBUF[OUT] =起始/地址的Buff[S]的起始/地址寄存器BUF[y]=/ /更高字节的结束AddiSRSXBUF[y]=Ey//Load字节结尾的AdvestRSXBUF[y]=FD/CRC1RXBUF(7)=DE//CRC2第一次检查CRC1和CRC2是否有效,如果ValueTrrxBuf(0)=01与设备ID匹配,则TrxBuf(1)=01与函数代码匹配,然后计算长度分配起始地址和长度存储值并检查CRC。tion
以上来自于百度翻译 以下为原文 Here i have attached my code sets. This is How i am using function 01 in my code. For Function3 its working fine. FOr function 1 i used to get error attached their screen shot. I also Tried MCC generated CRC hardware Check but it not working. Can someone guide using these CRC function in code Serial_Data() Is function i am calling in interrupt. I am checking first 8 byte of messages 01 01 00 00 00 31 fd de rxbuf[0]= 01 //device Id always rxbuf[1]= 01 //Functional code rxbuf[2]= 00 //higher byte of start address rxbuf[3]= 00 //Lower byte of start address rxbuf[4]= 00 //higher byte of end address rxbuf[5]= 31 //Lower byte of end address rxbuf[6]= FD //CRC1 rxbuf[7]= DE //CRC2 First i will check CRC1 & CRC2 is Valid or not if valid Get rxbuf[0]= 01 match with device ID then rxbuf[1]= 01 match with function code Then calculate length assign start address & length Store the values & check CRC again. #define READ_REG 1 static const unsigned long crc16_tab[] = { 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 }; unsigned short crc16(char * buf, unsigned short size) { unsigned int crc = 0; while (size--) crc = (crc << 8) ^ crc16_tab[(crc >> 8) ^ * buf++]; return crc; } void Serial_Data() { unsigned int address,crc1,crc2; unsigned char length,i; unsigned char Data_Len_Count; crc2=crc16(&rxbuf[0],6); // check first 6 byte. __delay_ms(10); if((rxbuf[6]==(unsigned char)(crc2))&&(rxbuf[7]==((unsigned char)(crc2>>8)))) { if(rxbuf[0]==Device_ID)// Checking Serial Data first byte match with Device Id or not { if(rxbuf[1]==READ_REG)// Checking Serial Data first byte match with Function code { // assigning start Address address=(((unsigned int)(rxbuf[2]<<8))+((unsigned int)(rxbuf[3]))); if(rxbuf[5]>=1) { length=rxbuf[5]; address=0X01; ser_data[0]=Device_ID; ser_data[1]=rxbuf[1]; ser_data[2]=length; ser_data[3]=00;// Put higher byte address Here ser_data[4]=01;// Put Lower byte address Here ser_data[5]=00; ser_data[6]=04; ser_data[7]=00; ser_data[8]=05; ser_data[9]=00; ser_data[10]=06; ser_data[11]=00; ser_data[12]=07; ser_data[13]=00; // Response message will start from Here crc_data[0]=Device_ID; crc_data[1]=rxbuf[1]; crc_data[2]=length; j=3; for(i=address;i<((address+length));i++) { crc_data[j++]=ser_data[i+3]; } crc1 =crc16(&crc_data[0],(length+3)); //crc function for response protocol from the device Serial_1_Send_byte(ser_data[0]); Serial_1_Send_byte(rxbuf[1]); Serial_1_Send_byte(ser_data[2]); for(i=address;i<((address+length));i++) { Serial_1_Send_byte(ser_data[i+3]); } Serial_1_Send_byte((unsigned char)crc1); Serial_1_Send_byte((unsigned char)(crc1>>8)); Serial_1_Send_byte(crc_m***); Serial_1_Send_byte(crc_l***); for(i=0;i<30;i++) { Serial_1_Send_byte(0); } } } __delay_ms(5); } } } earlier code look like below crc check function unsigned int crc_fn(unsigned char *dpacket,unsigned int len) // CRC Function(Error calcualtion) { unsigned int crc = 0xffff,poly = 0xa001; unsigned int i=0; for(i=0;i crc^= dpacket; for(j=0;j<8;j++) { if(crc & 0x01) { crc >>= 1; crc ^= poly; } else crc >>= 1; } } return (crc); } Attached Image(s) |
|
|
|
用下面的代码,我可以得到这种格式的数据。在这里我们可以看到来自PC的请求(主机运行良好)。当从设备[ ID ] [函数代码] [LeTHE]的回复正确后,不管我给出的是什么,我发送半字节的数据,而没有CRC计算,它不会发送超过6字节的数据,代码将在函数代码3上工作,在那里它可以发送100ByTee将CRC函数作为SUGG改变。EST,但结果不超过6字节01,长度01,00,00,00,00,这种格式只发送它。[代码]无符号int CRCffn(无符号char *dClb,无符号int ln)//CRC函数(错误计算){无符号int CRC=0xFFFF,POLY=0xAA1;未签名int=0;对于(i=0;I & lt;l++;i+){CRC ^=d封包;FO。r(j=0;j&lt;8;j++){if(CRC & AMP;0x01){CRC & gt;& gt;=1;CRC ^=Py;} ElSCRC&Gt;=1;} }返回(CRC);}
以上来自于百度翻译 以下为原文 With Below code i could able to get data in this format. Here we can see request from PC (master going well). When reply from slave [device ID] [function code] [ legth] coming properly after that whatever legth i gave i sending half byte of data without CRC calculation It wont send more than 6 byte of data, The code will work on function code 3 where it can send 100byte I have changes the CRC function as suggest but it result same not more than 6 byte 01 01 length 00 00 00 00 this format only it send respose. [code]unsigned int crc_fn(unsigned char *dpacket,unsigned int len) // CRC Function(Error calcualtion) { unsigned int crc = 0xffff,poly = 0xa001; unsigned int i=0; for(i=0;i crc^= dpacket; for(j=0;j<8;j++) { if(crc & 0x01) { crc >>= 1; crc ^= poly; } else crc >>= 1; } } return (crc); } Attached Image(s) |
|
|
|
我强烈建议你确保你的CRC代码首先工作,然后尝试与任何东西进行通信。按照他们的说法,分而治之。测试CRC应该很容易:你可以使用模拟器。创建一组消息并运行它们。如果CRC值检查所有这些,那么您可以安全地假定代码工作。
以上来自于百度翻译 以下为原文 I would strongly suggest that you ensure that your CRC code works first before trying to communicate with anything. Divide and conquer as they say. Testing the CRC should be easy: you can use the simulator for it. Create a bunch of messages and run them through. If the CRC value checks out for all of them then you can safely assume that code works. |
|
|
|
长度等于上限(RxBuf(5)/ 8),但是如果你有超过0xFF布尔值读,你必须改变公式。顺便说一下,CRC16就像+++你的CRCffn()也可以。
以上来自于百度翻译 以下为原文 the length equals ceiling( rxbuf[5]/8), so length=(rxbuf[5]<249)?(rxbuf[5]+7)/8:0x20;// function code 1 but if you have more than 0xFF booleans to read, you have to change the formula. by the way, the crc16 is like uint16_t crc16(char * buf, uint8_t size) { uint16_t crc = 0xFFFF; while (size--) { crc = (crc >> 8) ^ crc16_tab[ (crc ^ *buf++)&0xFF]; } return crc; } ++ your crc_fn() is ok, too. |
|
|
|
嗨,我觉得很遗憾的是,在PIC18FXXK40上有一个带有硬件CRC单元的PIC,而不是使用它。CRC单元可以在闪存或用户数据上使用。威廉希尔官方网站
简报TB3128给出了两个例子:http://WW1. Microchip。com/下载/ En/AppNodis/90003128A.pdf(可能是WR)。PIC16F1619,但它可以很容易地在PIC18上实现,因为我猜它是同一个外围设备。A1817的附注显示了如何将它用于闪存:HTTP:/WW1.MICCHIP.COM/DeLoSs/En/AppNoSe/90001817A.PDFRADGARDS
以上来自于百度翻译 以下为原文 Hi, I think it is really a pity to have a PIC with hardware CRC unit and not use it... On PIC18FxxK40, the CRC unit can be either used on the flash memory OR on user data. The technical brief TB3128 gives examples for both : http://ww1.microchip.com/downloads/en/AppNotes/90003128A.pdf (it is probably written for PIC16F1619 but it can be easily implemented on PIC18 as I guess it is the same peripheral The AN1817 appnote shows how to use it for flash memory : http://ww1.microchip.com/downloads/en/AppNotes/00001817A.pdf Regards |
|
|
|
我只想读50字节。我是数字状态Min 32,所以保持安全我保持50到100。我确信传入的消息,因为它工作在函数3并给出响应。当我通过函数时,我怀疑它的长度和地址,因为它可能不会创建CRC校验。我曾经得到7字节作为响应的输出已经附加。让我试试改变你的长度,然后再回来。请让我知道其他功能建议,我张贴将产生适当的CC或不。是否有任何方法检查正确的CRC是否生成。简单的模仿Excel表作为限制。可以指导任何好的计算工具吗????
以上来自于百度翻译 以下为原文 I want to read only 50 bytes. I e digital status min 32 so keeping safe I kept 50 to 100.i am sure about incoming message because it working on function 3 and give response. As I gone through function I suspect on length and address because of which it may not creating crc check. I used to get 7 byte as response who's output already attached. Let me try changing your length parm and get back. Please let me know the function other suggest and I have posted will generate proper cc or not. Is there any method to check proper crc generated or not. Simply modus excel sheet as restrictions. Can guide any good calculations tool??? |
|
|
|
只有小组成员才能发言,加入小组>>
5341 浏览 9 评论
2084 浏览 8 评论
1988 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3265 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2301 浏览 5 评论
846浏览 1评论
741浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
683浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
739浏览 0评论
630浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-2-12 01:24 , Processed in 1.631596 second(s), Total 111, Slave 95 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191