Hi,
I want to connect two MKR 485 SHIELDS (one as Master and the other as Slave) but I have a "timed out error" from the lasError function...
My wiring is :
MASTER | SLAVE
Y ======>A
Z ======>B
ISO GND ======>GND pin of MKR 485 Shield
The switch state is :
MASTER | SLAVE
Y-Z/ON ===Y-Z/OFF
HALF/ON
A-B/Off===A-B/ON
to check this out I have written this code :
MASTER CODE:
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>
void setup() {
Serial.begin(9600);
if (!ModbusRTUClient.begin(9600)) {
Serial.println("Failed to start Modbus RTU Client!");
while (1);
}
}
void loop() {
if (!ModbusRTUClient.requestFrom(0x01, HOLDING_REGISTERS, 0x00F3, 1)) { // make the call to the register
Serial.print("failed to read value! ");
Serial.println(ModbusRTUClient.lastError()); // error handler
} else {
uint16_t value = ModbusRTUClient.read(); // read data from the buffer
}
return value;
}
SLAVE CODE:
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>
void setup() {
Serial.begin(9600);
while (!Serial);
ModbusRTUServer.begin(0x01,9600);
}
void loop() {
ModbusRTUServer.holdingRegisterWrite(0x00F3, 15 );
ModbusRTUServer.holdingRegisterWrite(0x00F9, 10 );
ModbusRTUServer.holdingRegisterWrite(0x00FD, 8 );
delay(1000);
}
Thanks in advance for your help!