0

I'm trying to make modbus RS-485 connection between PC (Windows) and Arduino.

On the PC side I use USB-to-RS485 converter like this one http://ru.aliexpress.com/item/USB-to-485-RS485-converter-Adapter-Support-Windows-7-8-for-Arduino/1577970568.html

On the Arduino side I use TTL-to-RS-485 like this one http://ru.aliexpress.com/item/5pcs-lot-MAX485-Module-RS-485-TTL-to-RS485-Module-for-Arduino/32262338107.html

Problem1: When I send byte from PC to Arduino. Nothing happens. Arduino does not receive anything. In this case i upload to Arduino this code:

#include <SoftwareSerial.h>
#include "RS485_protocol.h"

SoftwareSerial rs485 (10, 11);  // receive pin, transmit pin
const byte ENABLE_PIN = 3;

void setup()
{
  Serial.begin(9600);
  rs485.begin (28800);
  pinMode (ENABLE_PIN, OUTPUT);  // driver output enable
}

void loop()
{ 
  byte buf [1];
  byte received = recvMsg (fAvailable, fRead, buf, sizeof (buf));

  if (received)
    {
      Serial.println(buf[0]);
    } else {
      Serial.println("--");
    }      
}  // end of loop

int fAvailable ()
  {
  return rs485.available ();  
  }

int fRead ()
  {
  return rs485.read ();  
  }

And open Serial Monitor in Arduino IDE to show received data. Then I open new instance of Arduino IDE, chose proper USB-to-RS485 COM port and opens it Serial Monitor to send some data.

So in Arduino side Serial Monitor I see only "--" lines. Even when I'm trying to send something in PC side Serial Monitor.

The other problem is:

Vice versa. When i sending some byte from Arduino to PC I receive some odd symbols instead sent byte.

The Arduino code in this case is:

#include <SoftwareSerial.h>
#include "RS485_protocol.h"

SoftwareSerial rs485 (10, 11);  // receive pin, transmit pin
const byte ENABLE_PIN = 3;

void setup()
{
  rs485.begin (28800);
  pinMode (ENABLE_PIN, OUTPUT);  // driver output enable

}

void loop()
{ 
  byte msg[1] = {3};
  sendMsg(msg);
}  // end of loop

void sendMsg(byte msg[])
{
  delay (1);  // give the master a moment to prepare to receive
  digitalWrite (ENABLE_PIN, HIGH);  // enable sending
  sendMsg (fWrite, msg, 1);
  digitalWrite (ENABLE_PIN, LOW);  // disable sending
}

void fWrite (const byte what)
  {
  rs485.write (what);  
  }

int fAvailable ()
  {
  return rs485.available ();  
  }

On the PC side (in the Arduino IDEs Serial Monitor) I receive odd symbols instead "3" symbol.

=======

RS485 converters wired with twisted pare A to A and B to B. RS485 to TTL converter connected to Arduino properly. (Communication between two arduinos works fine).

Please help.

Andrey Kryukov
  • 765
  • 1
  • 10
  • 23

1 Answers1

1

Example of RS485 :

Using a SN75176 IC.

enter image description here

RE (pin 2) connect to ground (for always reading )

Arduino control only DE PIN for writing data

But PC side problems:

  1. Where bridged DE pins ? (CTS,DTR,RTD if supported)
  2. What is your flow control ? (related #1)
  3. Did you connect any resistor to A, B pin ?<+5V>----[560R]-----(A)----[120R]-----(B)------[560R]------<-5V> So mean line end
  4. Did you filter DE Pin 2 signal (for noise)

A tricks : Use SN75176 on arduino side because this IC a RS232(UART) to (RS485) converter.

Edit : Modbus got 2 type on serial (RTU, ASCII). Dont care RS232/485 differences because different signal, same protocol.

Example packet type:

ASCII : :010300200004+CRC+FE(crc =packet check code, fe=end delimeter) RTU : \x01\x03\x00\x20\x00\x04\x +CRC On rtu : every byte need 1.5 char space and without start and end delimeter.

And Modbus node type meaning master and slave.

I hope helpfull.

dsgdfg
  • 1,492
  • 11
  • 18
  • Thank you. Very helpful for understanding RS485. My problem was in RS485_protocol.h library. It work fine when i connect two arduinos or two PC's. But not when i connect Arduino and PC. – Andrey Kryukov Feb 01 '16 at 03:06