Hi,
I'm using a arduino every ( ATMEGA4809) with library official from arduino, so i think this one ?
Modbus RTU 9600.
The arduino is the slave.
I had some issues of time consuming
"ModbusRTUServer.poll();" method so i made a measure and had these results :
- when the master is not polling any devices on modbus : 0 to 2ms maximum => Fine for me
- when the master pool the arduino device : 36-37ms => fine for me
- when the master pool another address :
ms: 7
ms: 500
ms: 7
ms: 500
ms: 8
ms: 500
ms: 8
ms: 500
So here there is a problem because it block my program for half a second when the master interrogate another device.
Do i need to configure something for to solve this ?
Is the library capable of doing 1 master with several slaves ?
Thanks
Best regards
#include <ArduinoRS485.h>
// ArduinoModbus depends on the ArduinoRS485 library
#include <ArduinoModbus.h>
// LED MODBUS
#define LEDMODBUS 7
// MODBUS
#define MODBUS_ADDRESS 102
#define MODBUS_INPUTREG 11
#define MODBUS_BAUDRATE 9600
// Variables General
unsigned int cycle;
/**********************************************/
/********** Setup *****************************/
/**********************************************/
void setup(void) {
byte i;
// LED Modbus
pinMode(LEDMODBUS, OUTPUT);
digitalWrite(LEDMODBUS, LOW);
Serial.begin(115200);
delay(500);
digitalWrite(LEDMODBUS, HIGH);
ModbusRTUServer.begin(MODBUS_ADDRESS, MODBUS_BAUDRATE);
ModbusRTUServer.configureInputRegisters(0x00, MODBUS_INPUTREG);
}
/**********************************************/
/********** Main LOOP *************************/
/**********************************************/
void loop(void) {
byte i;
digitalWrite(LEDMODBUS, LOW);
cycle = millis();
// Pool for modbus requests
ModbusRTUServer.poll();
cycle = millis() - cycle ;
if ( cycle > 2 )
{
Serial.print("ms: ");
Serial.println(cycle);
}
digitalWrite(LEDMODBUS, HIGH);
}