Hello everyone,
I am trying to communicate with a PR-36XW pressure sensor from Keller using modbus with an Arduino UNO. I am using the SensorModbusMaster.h library.
My sensor works well because I managed to get datas with a dedicated software from Keller using a USB-RS485 converter. So nothing wrong with the sensor.
I want to read the pressure value at the register adress 0x0002 with the function code 3, the ID of my sensor is 2. 2 registers are required to read the pressure value.
// ---------------------------------------------------------------------------
// Include the base required libraries
// ---------------------------------------------------------------------------
#include <Arduino.h>
#include <SensorModbusMaster.h>
// ---------------------------------------------------------------------------
// Set up the sensor specific information
// ie, pin locations, addresses, calibrations and related settings
// ---------------------------------------------------------------------------
// Define the sensor's modbus address
byte modbusAddress = 0x02; // The sensor's modbus address, or SlaveID
long modbusBaudRate = 9600; // The baud rate the sensor uses
// Define pin number variables
const int DEREPin = 5; // The pin controlling Recieve Enable and Driver Enable
// on the RS485 adapter, if applicable (else, -1)
// Setting HIGH enables the driver (arduino) to send text
// Setting LOW enables the receiver (sensor) to send text
// Construct software serial object for Modbus
#if defined(ARDUINO_AVR_UNO)
// The Uno only has 1 hardware serial port, which is dedicated to comunication with the computer
// If using an Uno, you will be restricted to using AltSofSerial or SoftwareSerial
#include <SoftwareSerial.h>
const int SSRxPin = 1; // Recieve pin for software serial (Rx on RS485 adapter)
const int SSTxPin = 0; // Send pin for software serial (Tx on RS485 adapter)
SoftwareSerial modbusSerial(SSRxPin, SSTxPin);
#else
// This is just a assigning another name to the same port, for convienence
// Unless it is unavailable, always prefer hardware serial.
HardwareSerial* modbusSerial = &Serial1;
#endif
// Construct the modbus instance
modbusMaster modbus;
// ---------------------------------------------------------------------------
// Main setup function
// ---------------------------------------------------------------------------
void setup()
{
// Set various pins as needed
if (DEREPin >= 0)
{
pinMode(DEREPin, OUTPUT);
}
// Turn on the "main" serial port for debugging via USB Serial Monitor
Serial.begin(57600);
// Turn on your modbus serial port
#if defined(ARDUINO_AVR_UNO)
modbusSerial.begin(modbusBaudRate);
// NOTE: Software serial only supports 8N1
#else
Serial1.begin(modbusBaudRate, SERIAL_8O1);
// ^^ use this for 8 data bits - odd parity - 1 stop bit
// Serial1.begin(modbusBaudRate, SERIAL_8E1);
// ^^ use this for 8 data bits - even parity - 1 stop bit
// Serial1.begin(modbusBaudRate, SERIAL_8N2);
// ^^ use this for 8 data bits - no parity - 2 stop bits
// Serial1.begin(modbusBaudRate);
// ^^ use this for 8 data bits - no parity - 1 stop bits
// Despite being technically "non-compliant" with the modbus specifications
// 8N1 parity is very common.
#endif
// Turn on debugging, if desired
//modbus.setDebugStream(&Serial);
// Start the modbus instance
modbus.begin(modbusAddress, modbusSerial, DEREPin);
// ---------------------------------------------------------------------------
// Main setup function
// ---------------------------------------------------------------------------
void loop()
{
// All values will be read as bigEndian
uint16_t pressure = 0;
pressure = modbus.float32FromRegister(0x03, 0x02, bigEndian);
Serial.print("Pressure:");
Serial.println(temperature);
Serial.println();
}
Here is the response :
pressure:0
RS485 Driver/Master Tx Enabled
RS485 Receiver/Slave Tx Enabled
Raw Request >>> {0x02, 0x03, 0x00, 0x02, 0x00, 0x02, 0x65, 0xF8}
Raw Response (63 bytes) <<< {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
Response is not from the correct modbus slave!
The raw request seems to be okay to me, but I don't understand why I am receiving a response that weird.
Do you have any idea of where the problem is ? Is it hardware or soft?
Thank you


