Problem whit simple-modbus

Hi to all, i am a newbie for modbus protocol and i want use it for read data from ducati energia smart piu' (it's a enrgy monitoring)
i want use a arduino uno and a max485 chip,
now i use a SimpleModbusMaster version 11, and i write this:

enum
{
  PACKET1,
  TOTAL_NO_OF_PACKETS // leave this last entry
};

packetPointer packet1 = &packets[PACKET1];
void setup()
{
// 0x13 is the address of data, 2 is the word, the  word i 16 bit, this value i read from manual of Ducati Energia   
 modbus_construct(packet1, 1, READ_HOLDING_REGISTERS, 0x13, 2, readRegs);
modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);
 }

void loop()
{
  modbus_update();
 lcd.print("requests:");
 lcd.print(packet1->requests);
 lcd.print("successful_requests: ");  
 lcd.print(packet1->successful_requests);
 lcd.print("failed_requests: ");  
 lcd.print(packet1->failed_requests);  
 lcd.print("exception_errors: ");  
 lcd.print(packet1->exception_errors); 
 lcd.print("Active energy: ");  
 lcd.print(readRegs[0]);
   delay(2000); 
 }

but don't work and i have this result
requests: 9
successful_requests: 0
failed_requests: 10
exception_errors:0
Active energy:0

i don't know where is the problem, can you help me?
Best reagrds
J.

can you help me?

Considering that the code you posted does not even compile, no.

this is my code:

#include <SimpleModbusMaster.h>
#include <LiquidCrystal.h>
//////////////////// Port information ///////////////////
#define baud 9600
#define timeout 1000
#define polling 200 // the scan rate

// If the packets internal retry register matches
// the set retry count then communication is stopped
// on that packet. To re-enable the packet you must
// set the "connection" variable to true.
#define retry_count 10

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

//#define LED 9
#define LED 3
// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
enum
{
  PACKET1,
 // PACKET2,
  TOTAL_NO_OF_PACKETS // leave this last entry
};

// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];
// Create a packetPointer to access each packet
// individually. This is not required you can access
// the array explicitly. E.g. packets[PACKET1].id = 2;
// This does become tedious though...
packetPointer packet1 = &packets[PACKET1];
//packetPointer packet2 = &packets[PACKET2];
// Data read from the arduino slave will be stored in this array
// if the array is initialized to the packet.
unsigned int readRegs[1];
// Data to be written to the arduino slave
//unsigned int writeRegs[1];

LiquidCrystal lcd(12, 11, 9, 8, 7, 6);  //  LCD configuration
void setup()
{
   // read 1 register starting at address 0
 // 0x13 is the address of data, 2 is the word, the  word i 16 bit, this value i read from manual of Ducati Energia 
  modbus_construct(packet1, 1, READ_HOLDING_REGISTERS, 0x13, 2, readRegs);
  
// configuration
  modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);
    pinMode(LED, OUTPUT);
}

void loop()
{
  modbus_update();
  
  
   lcd.print("requests:");
  lcd.print(packet1->requests);
  lcd.print("successful_requests: ");  
  lcd.print(packet1->successful_requests);
  lcd.print("failed_requests: ");  
  lcd.print(packet1->failed_requests);  
  lcd.print("exception_errors: ");  
  lcd.print(packet1->exception_errors); 
  lcd.print("Active energy: ");  
  lcd.print(readRegs[0]);
  delay(2000); 
  
}

What about providing the necessary information? A link to the library used, the hardware on the other side (datasheet) and a diagram or photo of the wiring would be a good starting point.

Do you really think that configuring the ModBus library after you already used it (that's how you do it in setup()) makes sense?

i use this shield

you can read the schematic of shield,
In the shield i disable tx echo and consigure in this way the SWN, put up on the 1 and put up off 2 and 3

i use pin 12, 11, 9, 8, 7, 6 for lcd LCM1602C for read value

There are multiple libraries out there that include a SimpleModbusMaster.h file. Don't waste our time and provide a link to the version you're using!

Make a photo of your setup or at least draw a wiring diagram that shows all connections. How did you wire the energy monitor to the Arduino shield?

in this link MassaBUS incontra Arduino - Massari Electronics you can read
the scematic,
i connect whit a tisted wire the A connector of shiled and A connector of Energy monitoring and the B connector of shiled with B connector of Energy monitoring.

The energy monitor is work well because i use a "TCP/IP Ethernet to Serial RS232 RS485 RS422 Converter" for comunicat with it,
i use this program: modpoll

modpoll -1 -f -m enc $IP -p $PORT -a $ADDR -c $CARD -r $PARAM
this is my configuration:

IP=192.168.1.121
PORT=2000
ADDR=31
PARAM=4
CARD=2

now i hope answer all you request

Still no link to the library you're using.

Where in your sketch did you specify the address of the energy meter?

hi i try whit modpoll program and the energymneter work well
i use this configuration
modpoll -1 -f -b9600 -s1 - p none -m rtu -a 5 - c2 -r20 COM13

-a 5, 5 is addrress of energy meter
-c , 2 is number of values of poll

  • r 20 , 20 is the start reference

best regards
j.

Hi jocker99,

A few questions in order for me to help you:

  1. What version of Arduino IDE are you using and what board?
  2. Please provide a connect schematic.
  3. Please provide your sketch.
  4. and finally please provide the modbus address data sheet for your device (most important!!)

I will then be able to help you.

Some posts ago I asked you that question:

There are multiple libraries out there that include a SimpleModbusMaster.h file. Don't waste our time and provide a link to the version you're using!

and you still didn't answer it.

And I detail my last question:

Where in your sketch did you specify the address of the energy meter?

That question depends very much on the answer to the first question of this post so please answer both this time.