Hi All
I am back.
Fortunately I got a system which has Teensy 3.2 as its controller. The system has one SPI Display also. The system is used to display the value(Angle) from the Modbus - RTU based Angular transducer. I tested the system and found that it is correctly displaying the value coming from Angular transducer. The system has also MAX3485 IC interface for Modbus connections. But I do not have the code of the Teensy 3.2 installed in the system.
So I tried a sample code(Modbus RTU Temperature Sensor) with a
spare teensy 3.2 to get values from
Angular transducer using Arduino Modbus library. But was unsuccessful. I am not interested about the LCD display part. But I think the code shall be able to display values on serial monitor. When I run the code, I am getting "failed to read registers! Connection timed out" on the serial monitor.
Before posting the sample code I may prefer to state here the connections between Teensy and MAX3485 IC.
1. MAX4385 is powered from 3.3 v supply from Teensy.
2. RE & DE pins of MAX3485 are shorted together and connected to 6th pin of Teensy.
3. RO & DI pins of MAX3485 are connected to Modbus device (here the Angular transducer).
Regarding Modbus device (
https://www.usdigital.com/media/vxsibyx1/t7_modbus_communication_user_guide_2.pdf) it is inclinometer made by US Digital (
https://www.usdigital.com/products/inclinometers/T7) and has serial configuration
Add-12, 38400 baud, 8 data bits, even parity and 1 stop bit.
https://www.usdigital.com/products/inclinometers/T7
https://www.usdigital.com/media/vxsibyx1/t7_modbus_communication_user_guide_2.pdf
As earlier advised by Mr. PaulStoffregen I have changed the default PIN configuration to 6 in RS485.h as given below ,
#ifdef __AVR__
#define RS485_DEFAULT_DE_PIN 6
#define RS485_DEFAULT_RE_PIN -1
#else
#define RS485_DEFAULT_DE_PIN 6
#define RS485_DEFAULT_RE_PIN -1
#endif
Also I tested the voltage level of Teensy PIN-6 by changing pre delay and post delay to 500ms in the RS485.h
#define RS485_DEFAULT_PRE_DELAY 50
#define RS485_DEFAULT_POST_DELAY 50
And I found the DE&RE pin voltage level is rising to 3.3 volts and then back to zero.
Please find my sample code below. Kindly suggest the rectifications needed for establishing Modbus communication.
#include <ArduinoModbus.h>
float Ang1;
float Ang2;
void setup() {
Serial2.begin(38400,SERIAL_8E1);
while (!Serial2);
Serial.println("T7_Inclinometer");
// start the Modbus RTU client
if (!ModbusRTUClient.begin(38400)) {
Serial.println("Failed to start Modbus RTU Client!");
while (1);
}
}
void loop() {
// send a Holding registers read request to (slave) id 12, for 2 registers
if (!ModbusRTUClient.requestFrom(12, HOLDING_REGISTERS, 0x01, 2)) {
Serial.print("failed to read registers! ");
Serial.println(ModbusRTUClient.lastError());
} else {
// If the request succeeds, the sensor sends the readings, that are
// stored in the holding registers. The read() method can be used to
// get the raw temperature and the humidity values.
short rawAng1 = ModbusRTUClient.read();
short rawAng2 = ModbusRTUClient.read();
// To get the temperature in Celsius and the humidity reading as
// a percentage, divide the raw value by 10.0.
Ang1 = rawAng1 / 10.0;
Ang2 = rawAng2 / 10.0;
Serial.println(Ang1);
Serial.println(Ang2);
}
delay(5000);
}