Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Giving portenta error #196

Open
DineshMudumala opened this issue Aug 28, 2024 · 0 comments
Open

Giving portenta error #196

DineshMudumala opened this issue Aug 28, 2024 · 0 comments

Comments

@DineshMudumala
Copy link

DineshMudumala commented Aug 28, 2024

hlo i am using portenta machine control which uses portenta H7 as base to read a float values in the slave i am currently using this code

#include <ModbusMaster.h>
#include "Arduino_PortentaMachineControl.h"

ModbusMaster modbus;

void setup() {
Serial.begin(9600);
while (!Serial) {
;
}

delay(1000);
Serial.println("Start RS485 initialization");

// Initialize RS485 communication
MachineControl_RS485Comm.begin(9600, 0, 500); // Specify baudrate, and preamble and postamble times for RS485 communication

// Start in receive mode
MachineControl_RS485Comm.receive();

// Initialize Modbus communication
modbus.begin(1, MachineControl_RS485Comm); // Slave ID 1, use MachineControl_RS485Comm as Serial

Serial.println("Initialization done!");

}

void loop() {
// Read floating-point value from Modbus holding register address 1107
uint8_t result = modbus.readHoldingRegisters(1107, 2); // Read 2 registers (4 bytes for float)

if (result == modbus.ku8MBSuccess) {
    // Data received successfully
    uint16_t highByte = modbus.getResponseBuffer(0); // Get high byte
    uint16_t lowByte = modbus.getResponseBuffer(1);  // Get low byte
    
    // Combine high and low bytes to form a 32-bit float
    uint32_t floatBits = ((uint32_t)highByte << 16) | lowByte;
    float value;
    memcpy(&value, &floatBits, sizeof(float));

    Serial.print("Float value: ");
    Serial.println(value, 6); // Print float with 6 decimal places
} else {
    Serial.print("Modbus Read Error: ");
    Serial.println(result);
}

}
which is returning E2 as error don't know y could you guys please help it would mean a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant