Problemi comunicazione MODBUS [RISOLTO]

Ciao Paolo,
grazie per le letture
modificando opportunamenteil codice Slave che hai suggerito con:

 modbus_configure(9500, 1, 2, TOTAL_REGS_SIZE);

per monitorare i dati ho pensato di usare un lcd in questo modo:

#include <SimpleModbusMaster.h>
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 8);
 

// led to indicate that a communication error is present
#define connection_error_led 13

//////////////////// 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 

// 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,
  // leave this last entry
  TOTAL_NO_OF_PACKETS
};

// Create an array of Packets for modbus_update()
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];


// The data from the PLC will be stored
// in the regs array
unsigned int regs[9];

void setup()
{
   
  lcd.begin(16, 2);
  
  
  
  
  // read 3 registers starting at address 1
  packet1->id = 2;
  packet1->function = READ_HOLDING_REGISTERS;
  packet1->address = 1;
  packet1->no_of_registers = 3;
  packet1->register_array = regs;
  
 
  
  // P.S. the register_array entries above can be different arrays
  
  // Initialize communication settings etc...
  modbus_configure(baud, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);
  
  pinMode(connection_error_led, OUTPUT);
}

void loop()
{
  unsigned int connection_status = modbus_update(packets);
  
  if (connection_status != TOTAL_NO_OF_PACKETS)
  {
    digitalWrite(connection_error_led, HIGH);
    // You could re-enable the connection by:
    //packets[connection_status].connection = true;
    lcd.print("errore ricezione");
  }
  else
    digitalWrite(connection_error_led, LOW);
  lcd.print("Dati ricevuti");
  // update the array with the counter data
  regs[3] = packet1->requests;
  regs[4] = packet1->successful_requests;
  regs[5] = packet1->total_errors;
 // lcd.setCursor(0, 1);
  // vorrei vedere qualche dato:
 // lcd.print("qualche dato???");
}

indovina cosa mi apapre sull' lcd ???

errore ricezione

hai idea quale sia l' errore?

Luca