SimpleModbusMaster function 06

Hi all,

I’m working on a project where my Arduino is used as a Modbus RTU master to control a stepper motor. I’m currently trying to use the SimpleModbusMaster library.

I have two steppers (ID1 and ID2) that I’d like to give a command (move to a specific position). This command can be written in a single register, which is specified in Modbus RTU as function code 06.

Using my computer and test software I’m perfectly able to execute the commands and the steppers will react correctly. The message that goes out for the first stepper is has to be:

0x01 (Slave ID)
0x06 (Function Code)
0x00 (Register byte 1)
0x7D (Register byte 2)
0x00 (Data byte 1)
0x08 (Data byte 2)
0x18 (Checksum byte 1)
0x14 (Checksum byte 2)

However, with the sketch below the data that comes out is always <0x00 0x00> instead of <0x00 0x08>. The sketch is a standard example from the forum that I’ve slightly altered.

I can’t figure out what I’m doing wrong. Could anybody shine some light on the subject? Thanks!!

#include <SimpleModbusMaster.h>

//////////////////// Port information ///////////////////
#define baud 115200
#define timeout 500
#define polling 200 // the scan rate
#define retry_count 10

// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 2 

//#define LED 9

// The total amount of available memory on the master to store data

// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.

  TOTAL_NO_OF_PACKETS // leave this last entry

// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];

// Masters register array
unsigned int regs[TOTAL_NO_OF_REGISTERS];

void setup()
  // Initialize each packet  if(afwisseling==0){
  modbus_construct(&packets[PACKET1], 1, PRESET_SINGLE_REGISTER, 0x7D, 8, 0);
  modbus_construct(&packets[PACKET2], 2, PRESET_SINGLE_REGISTER, 0x7D, 9, 0); 
  // Initialize the Modbus Finite State Machine
  modbus_configure(&Serial, baud, SERIAL_8E1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);

void loop()

Anybody? :-)