Simple ModBus Master function 15 I have a simple setup with arduino Nano as slave and a arduino Mega as master
Can anyone explain how the function 15
FORCE_MULTIPLE_COILS
Works
i have been running some test on this
and cant figure out how to use the
local_start_address
is this the data to read from
or
is it a pointer to another File
modbus_construct(&amp;packets[PACKET1], 1, 15, 1, 8, 1021);
dec 8 = (no_of_registers = packet-&gt;data)  // number of coils
so frame 6 = 1 (frame[6] = no_of_bytes;) // number of bytes more
dec 1021 = (packet-&gt;local_start_address)
the dec 1021 and 65565 seams to work ????
but makes no sense to me in binary format ?
Here is
part of CPP file:
enter code here

unsigned char construct_F15()
{
   // function 15 coil information is packed LSB first until the first 16 bits are completed
  // It is received the same way..
  unsigned char no_of_registers = packet-&gt;data / 16;
  unsigned char no_of_bytes = no_of_registers * 2;
   
  // if the number of points dont fit in even 2byte amounts (one register) then use another register and pad
  if (packet-&gt;data % 16 &gt; 0)
  {
    no_of_registers++;
    no_of_bytes++;
  }
   
  frame[6] = no_of_bytes;
  unsigned char bytes_processed = 0;
  unsigned char index = 7; // user data starts at index 7
   unsigned int temp;
   
  for (unsigned char i = 0; i &lt; no_of_registers; i++)
  {
    temp = register_array[packet-&gt;local_start_address + i]; // get the data

frame[index] = temp &amp; 0xFF;

    bytes_processed++;
     
    if (bytes_processed &lt; no_of_bytes)
    {
      frame[index + 1] = temp &gt;&gt; 8;
      bytes_processed++;
      index += 2;
    }
  }
   unsigned char frameSize = (9 + no_of_bytes); // first 7 bytes of the array + 2 bytes CRC + noOfBytes
   return frameSize;
}
i found it
it is the
temp = register_array[packet-&gt;local_start_address + i]; // get the data
in the ccp file
register_array[packet-&gt;local_start_address + i]
its pointing to the wrong location... register_array??
supersized no one has noticed this as long as the simple modbus master for adruino
has been used ?
or i have a bad CPP file ?
i have temp corrected this by replacing with
unsigned char construct_F15()
{
    // function 15 coil information is packed LSB first until the first 8 bits are completed
    unsigned char frameSize = 10;
    unsigned char temp;
    frame[6] = 1;
    frame[7] = packet-&gt;local_start_address ^ 0XFFFF; 
    return frameSize;
}

works (0 = off / 255 = on)
modbus_construct(&amp;packets[PACKET1], 1, 15, 1, 8, 0); // 1 thru 8 = off
modbus_construct(&amp;packets[PACKET2], 1, 15, 1, 8, 255); // 1 thru 8 = on