I'm trying to learn how to talk to my modbus slave by trying to do a simple request and then build the software up
bit by bit. I'm using a max485 wired w/ an uno card. The wiring is the basic seen all over the internet, namely
Max - UNO
RO to RX
DO to TX
RE and DE tied together and controlled from pin 3 on the uno. I do have a terminating 27ohm resister across A and B as per the max485 data sheet.
Power and GND and A and B going to A and B on the modbus device. I do have the uno GND going to the GND on the modbus
device. I can see the request going out over lines A and B, but I get no response. Voltages from GND to A ~ 3.4v,
from GND to B ~1.4v.
Note: I tried a USB -RS485 cable with the FTDI chips and vendor software (checked slave address, comm parameters) to the modbus device and it works ok. So i know the unit is good. I've seen other users use this configuration and their designs seem to work, so I believe my wiring is ok. The software, I think is simple enough to get a single response; unless I'm just really missing something.
Any help from an Arduino / Modbus / Programming God would be met with a candle burning under their picture in my living room.
Kind Regards, HuaTian.
//Slave addr is 1, query coil 3, addr 9c45, 1 register
byte message[] = {0x01,0x03,0x9c,0x45,0x00,0x01,0xbb,0xef}; // <- Query holding register w/ a valid CRC.
char inBound;
void setup() {
Serial.begin(9600);
pinMode(0,INPUT); //RX
pinMode(1,OUTPUT); //TX
}
void loop() {
digitalWrite(3,HIGH); //Tx
Serial.write(message,sizeof(message)); //Send message
digitalWrite(3,LOW); //Rx should receive something / anything
if (Serial.available() > 0 )
{ inBound = Serial.read();
Serial.println(inBound);}
delay(1000); //Wait 1 seconds for Modbus to respond
}