Dear all,
I am trying to integrate arduino with modbus RTU protocol. Using previous library i could able to use Holding register i.e function 3 with system. Now i would like to implement using function code 1. Is there any c example code used for reading coil function.
Below function i used to get function 3 & its working fine. Is there any changes to be made to work on function 0X01
nsigned 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<len;i++)
{
crc^= dpacket[i];
for(j=0;j<8;j++)
{
if(crc & 0x01)
{
crc >>= 1;
crc ^= poly;
}
else
crc >>= 1;
}
}
return (crc);
}
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.