I am trying to use my Arduino opta for measuring energy meter readings using RS485. I can scan them using modbus poll but when using arduino opta, I always get connection timed out error. I am using the structure followed on the guides on OPTA for energy meter readings. I have also attached modbus poll and energy meter modbus register map. I have used node, Modbus Master but still getting same issue. No parity and 1 bit.
#include "stm32h7xx_ll_gpio.h"
#include <ArduinoModbus.h>
#include <ArduinoRS485.h>
constexpr auto baudrate { 9600 };
constexpr auto bitduration { 1.f / baudrate };
constexpr auto preDelayBR { bitduration * 9.6f * 3.5f * 1e6 };
constexpr auto postDelayBR { bitduration * 9.6f * 3.5f * 1e6 };
#define F7M24 0x01
uint8_t readInputRegisterValues(int dev_address, uint8_t reg_address, int byte_count){
uint8_t packet;
if (!ModbusRTUClient.requestFrom(dev_address, INPUT_REGISTERS, reg_address, byte_count)) {
Serial.print("failed! ");
Serial.println(ModbusRTUClient.lastError());
return 0;
} else {
Serial.println("success");
while (ModbusRTUClient.available()) {
packet = ModbusRTUClient.read();
Serial.println(packet);
}
return packet;
}
}
void modbus_com_actual(){
// Actual Measurements
// Voltage (V)
V_actual = readInputRegisterValues(F7M24, 1, 2);
delay(100);
}
void setup(){
Serial.println("Energy Management - Modbus RTU Client");
RS485.setDelays(preDelayBR, postDelayBR);
// start the Modbus RTU client
// 7M.24 Energy meter specifies 19200 of default baudrate and 8N2 frame
if (!ModbusRTUClient.begin(baudrate, SERIAL_8N1)) {
Serial.println("Failed to start Modbus RTU Client!");
while (1)
;
}
}
void loop(){
modbus_com_actual();
}
77d468606ec32db2211614467242ca28_OP MFM376 Series OP506-V03 12-08-19.pdf (531.2 KB)