Closed
Description
Trying the modbus library with the following sketch:
#include <ArduinoModbus.h>
float temperature, humidity;
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("Modbus Temperature Humidity Sensor");
if (!ModbusRTUClient.begin(9600)) {
Serial.println("Failed to start Modbus RTU Client!");
while (1);
}
}
int i=0;
void loop() {
if (!ModbusRTUClient.requestFrom(1, HOLDING_REGISTERS, 0x00, 2)) {
Serial.print("failed to read registers! ");
Serial.println(ModbusRTUClient.lastError());
} else {
short rawtemperature = ModbusRTUClient.read();
short rawhumidity = ModbusRTUClient.read();
temperature = rawtemperature / 10.0;
humidity = rawhumidity / 10.0;
Serial.println(temperature);
Serial.println(humidity);
}
Serial.println(i);
delay(1000);
i++;
if(i>2){
while(1);
}
}
rise an issue related to reception of the packet from the RS485 channels, it alternate a good reception with a discard, as show in the in the image.
I have sniffed the channel with the Saleae analyzer, and the packet are the same, the capture are in the following .zip.
The problem could be located in the library libmodusb/modbus.c in modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest)
or in the integrity check function of the class modbus_backend_type_t.
In particular must be checked how the CRC is calculated in two consecutive reading from the RS485 .
Following, also, a stamp of serial monitor output:
Metadata
Metadata
Assignees
Labels
No labels