Skip to content

Giving portenta error #196

@DineshMudumala

Description

@DineshMudumala

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions