Thanks for suggestions..
I tried following things :
- Changed Arduino board and RS485-TTL module, to avoid chance of problem due to false hardware.
- Created A slave on PC using Modsim32 just to verify established communication.
- Used LCD (connection diagram is attached here.)
- Modified my code excluding SoftwareSerial library.
- Reinstalled ModbusMaster libtary to clean up the mess earlier created by myself.
- Tried modifying Baud rate(to 9600).
- Interchanged Pins D+ and D- as well as DI and RO.
Still i am getting same "result : 226 ", but, this time on LCD.
I guess Something is to be done with enable pin of RS485-TTL converter.
what possibly be wrong?
#include <LiquidCrystal.h>
#include<ModbusMaster.h>
#define DirectionControl 3
ModbusMaster node;
const int rs = 12, en = 11, d4 = 6, d5 = 5, d6 = 4, d7 = 3;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
Serial.begin(9600,SERIAL_8N2);
node.begin(1,Serial);
lcd.begin(16, 2);
pinMode(DirectionControl, OUTPUT);
digitalWrite(DirectionControl, 1);
lcd.clear();
lcd.print("Setup done!");
}
void loop() {
static uint32_t i,data;
uint8_t result;
i++;
node.setTransmitBuffer(0,lowWord(i));
node.setTransmitBuffer(1,highWord(i));
result= node.readHoldingRegisters(1,1);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(result);
if (result == node.ku8MBSuccess)
{
data = node.getResponseBuffer(0);
}
lcd.setCursor(0,1);
lcd.print(data);
}