update modbus
This commit is contained in:
@@ -12,20 +12,16 @@
|
||||
**************************************************/
|
||||
u16 modbus_lib_crc16(u8 *p_data, u16 len)
|
||||
{
|
||||
u16 crc16 = 0xffff;
|
||||
u16 i;
|
||||
while(len--)
|
||||
{
|
||||
crc16 = crc16^(*p_data++);
|
||||
for(i=0; i++<8; )
|
||||
{
|
||||
if(crc16&0x0001)
|
||||
{
|
||||
crc16 = (crc16>>1)^0xa001;
|
||||
}
|
||||
else
|
||||
{
|
||||
crc16>>=1;
|
||||
u16 crc16 = 0xFFFF;
|
||||
u16 i, j;
|
||||
for (i = 0; i < len; i++) {
|
||||
crc16 ^= p_data[i];
|
||||
for (j = 0; j < 8; j++) {
|
||||
if (crc16 & 0x0001) {
|
||||
crc16 >>= 1;
|
||||
crc16 ^= 0xA001;
|
||||
} else {
|
||||
crc16 >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,7 +193,7 @@ void modbus_lib_data_read(u8 id,u16 addr,u16 num,void (*send)(u8 *,u16 ))
|
||||
u8 tx[8];
|
||||
u16 crc16;
|
||||
tx[0] = id;
|
||||
tx[1] = 0x41;//0x03;
|
||||
tx[1] = 0x03;//0x03;
|
||||
tx[2] = (addr >> 8) & 0xff;
|
||||
tx[3] = addr & 0xff;
|
||||
tx[4] = (num >> 8) & 0xff;
|
||||
|
||||
Reference in New Issue
Block a user