EDIT real Solution:
I did not know explain. Now I know. ![]()
-1 Master and 6 slaves. (or more, or less)
-Slaves gave many errors if they spoke together. (Slaves sometimes stopped working! )
-Slaves were very well if they were called just one. ![]()
-Do not know why. If each slave was fine alone, why they went wrong if together?
(I was going crazy) =(
The problem was that reading 18B20 12-bit resolution is VERY SLOW. 750ms for reading. All slaves had 18B20.
Simplemodbus works poorly if there is delay in the slave. I think after the timeout slaves respond. I think buffer problem.
The solution: Read 18B20 dallastemperature asynchronously.
Here's how to:
http://forum.arduino.cc/index.php?topic=61840.5
I hope to help someone.
Hello
I have a problem with SimpleModbus and waits.
Slaves SimpleModbus stops responding with long waits. Sometimes, after a few minutes! becomes responsive, but usually never ever responds. It is necessary to reset the slave.
If we read temperature "DallasTemperature" and OneWire, the code has long waits. > 1000ms
I do not understand why he does this. It is possible a solution?
Thanks
#include <SimpleModbusSlave.h>
#define LED 9
enum
{
ADC_VAL,
PWM_VAL,
kkk ,
kkk2,
kkk3,
mmmm,
llll,
HOLDING_REGS_SIZE // leave this one
};
unsigned int holdingRegs[HOLDING_REGS_SIZE]; // function 3 and 16 register array
void setup()
{
modbus_configure(&Serial, 9600, SERIAL_8N2, 4, 2, HOLDING_REGS_SIZE, holdingRegs);
}
unsigned long tiempo;
#define RETARDO_SENSORES 10000
void loop()
{
modbus_update();
holdingRegs[ADC_VAL] = 888;
holdingRegs[kkk] = 444;
holdingRegs[kkk2] = 4445;
if(millis() - tiempo > RETARDO_SENSORES){
delay(1500);
}
}
#include <SimpleModbusMaster.h>
#define baud 9600
#define timeout 500
#define polling 200 // the scan rate
#define retry_count 100
#define TxEnablePin 2
enum
{
PACKET1,
TOTAL_NO_OF_PACKETS // leave this last entry
};
Packet packets[TOTAL_NO_OF_PACKETS];
packetPointer packetSalon = &packets[PACKET1];
unsigned int RegistrosSalon[11];
void setup()
{
Serial.begin(115200);
modbus_construct(packetSalon, 4, READ_HOLDING_REGISTERS, 0, 7, RegistrosSalon);
modbus_configure(&Serial1, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);
}
unsigned long tiempo=0;
void loop()
{
modbus_update();
if(millis() > tiempo+3000){
Serial.println("");
Serial.print("SALON->Paquetes_OK: ");
Serial.print(packetSalon->successful_requests);
Serial.print(" SALON->Paquetes_MAL: ");
Serial.println(packetSalon->failed_requests);
Serial.print("Resultados: ");
Serial.println(RegistrosSalon[0]);
Serial.print("Temp Salon: ");
Serial.println(RegistrosSalon[1]);
Serial.print("Luz Salon: ");
Serial.println(RegistrosSalon[2]);
Serial.print("Tiempo PIR Salon: ");
Serial.println(RegistrosSalon[3]);
Serial.println(RegistrosSalon[4]);
Serial.print("Errores transmision: ");
Serial.println(RegistrosSalon[5]);
tiempo=millis();
}
}