Ciao, ho seguito le tue indicazioni e tutto funziona a dovere.
Ora sto cercando di fare un passettino in avanti, ovvero da un master voglio comandare 2 slave. Di conseguenza ho aggiunto un secondo pacchetto telegram con stessi parametri (funzione, numero di registri...) in cui cambia solo l'id dello slave.
Anche in questo caso funziona (invia i pacchetti in due momenti separati, la prima volta interroga lo slave 1, la seconda lo slave 2...se volessi inviarli contemporaneamente?).
Ho provato quindi ad associare al primo valore dell'array=au16data[0] un valore letto da seriale, ovvero:
if(Serial.read()=='i'){
au16data[0]=1;}
if(Serial.read()=='f'){
au16data[0]=0;}
Legge correttamente 'i' (i led dei due slave si accendono solo se digito tale carattere da seriale), ma sull' 'f' niente risposta...dove sto sbagliando?
Riporto comunque lo sketch completo di master e dello slave
master
#include <ModbusRtu.h>
#include <SoftwareSerial.h>
uint16_t au16data[]={0,0,0}; //!< data array for modbus network sharing Array
uint8_t u8state; //!< machine state
uint8_t u8query; //!< pointer to message query
SoftwareSerial mySerial(3,5);
Modbus master(0);
modbus_t telegram[2];
unsigned long u32wait;
void setup() {
Serial.begin(9600);
master.begin(&mySerial, 9600); // baud-rate at
master.setTimeOut(9600); // if there is no answer in 2000 ms, roll over
u32wait = millis() + 1000;
u8state = 0;
}
void loop() {
switch( u8state ) {
case 0:
if (millis() > u32wait) u8state++; // wait state
break;
case 1:
if(Serial.read()=='i'){
au16data[0]=1;}
if(Serial.read()=='f'){
au16data[0]=0;}
telegram[0].u8id = 1; // slave address
telegram[0].u8fct = 6; // function code (this one is registers read)
telegram[0].u16RegAdd = 0; // start address in slave
telegram[0].u16CoilsNo = 1; // number of elements (coils or registers) to read
telegram[0].au16reg = au16data; // pointer to a memory array in the Arduino
telegram[1].u8id = 2; // slave address
telegram[1].u8fct = 6; // function code (this one is registers read)
telegram[1].u16RegAdd = 0; // start address in slave
telegram[1].u16CoilsNo = 1; // number of elements (coils or registers) to read
telegram[1].au16reg = au16data; // pointer to a memory array in the Arduino
master.query( telegram[u8query] ); // send query (only once)
u8state++;
u8query++;
if (u8query > 2) u8query = 0;
break;
case 2:
master.poll(); // check incoming messages
if (master.getState() == COM_IDLE) {
u8state = 0;
u32wait = millis() + 100;
}
break;
}
}
slave (uguale per entrambi, cambia solo l'id)
#include<ModbusRtu.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3,5);
uint16_t modbus_array[] = {0,0,0};
Modbus bus(1,5,13);
void setup() {
Serial.begin(9600);
delay(1000);
pinMode(9, OUTPUT);
bus.begin(&mySerial,9600);
}
void loop() {
bus.poll(modbus_array,sizeof(modbus_array)/sizeof(modbus_array[0]));
if (modbus_array[0] == 1){
digitalWrite(9,HIGH);
} else {
digitalWrite(9,LOW);
}
}
Nel frattempo c'ho buttato dentro anche la software serial... 
Grazie.