|
|
I’m working on a Modbus RTU communication setup between an Arduino Opta (as Master) and a Dacai HMI (as Slave) using RS-485.
My goal is to send random float data from the Opta to be displayed on the HMI screen.
Below i attached arduino Opta (Master) Code
- #include <ArduinoRS485.h>
- #include <ModbusMaster.h>
- constexpr uint32_t BAUDRATE = 9600;
- constexpr uint8_t HMI_SLAVE_ID = 1;
- constexpr uint16_t HMI_REG_ADDR = 0x9C41; // Dacai HMI register address
- ModbusMaster node;
- void setup() {
- Serial.begin(115200);
- RS485.begin(BAUDRATE);
- node.begin(HMI_SLAVE_ID, RS485);
- Serial.println("Modbus RTU Master started...");
- }
- void loop() {
- float randomFloat = random(0, 10000) / 100.0; // Random 0.00–100.00
- union { float f; uint16_t words[2]; } floatData;
- floatData.f = randomFloat;
- node.setTransmitBuffer(0, floatData.words[0]);
- node.setTransmitBuffer(1, floatData.words[1]);
- uint8_t result = node.writeMultipleRegisters(HMI_REG_ADDR, 2);
- if (result == node.ku8MBSuccess)
- Serial.println(randomFloat);
- else {
- Serial.print("Modbus Error: 0x");
- Serial.println(result, HEX);
- }
- delay(2000);
- }
复制代码
Also i have attached photo of Slave Configuration
The Opta is continuously reporting the following error:
Modbus Error: 0xE2
Can Anyone Help me to solve this ?
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|