0

PC (Windows) と Arduino を modbus RS-485 で接続しようとしています。

PC 側では、このような USB-to-RS485 コンバーターを使用しますhttp://ru.aliexpress.com/item/USB-to-485-RS485-converter-Adapter-Support-Windows-7-8-for-Arduino /1577970568.html

Arduino 側では、このような TTL-to-RS-485 を使用しますhttp://ru.aliexpress.com/item/5pcs-lot-MAX485-Module-RS-485-TTL-to-RS485-Module-for- Arduino/32262338107.html

問題 1: PC から Arduino にバイトを送信するとき。何も起こりません。Arduino は何も受信しません。この場合、Arduino に次のコードをアップロードします。

#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 ();  
  }

受信したデータを表示するには、Arduino IDE でシリアル モニターを開きます。次に、Arduino IDE の新しいインスタンスを開き、適切な USB-to-RS485 COM ポートを選択し、シリアル モニタを開いてデータを送信します。

そのため、Arduino側のシリアルモニターには「--」行しか表示されません。PC側のシリアルモニターで何かを送信しようとしているときでも。

他の問題は次のとおりです。

逆に。ArduinoからPCにバイトを送信すると、送信されたバイトの代わりに奇妙なシンボルがいくつか受信されます。

この場合の Arduino コードは次のとおりです。

#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 ();  
  }

PC 側 (Arduino IDE のシリアル モニター) では、"3" シンボルの代わりに奇数のシンボルが表示されます。

=======

ツイストペア A から A および B から B で配線された RS485 コンバーター。 Arduino に適切に接続された RS485 から TTL コンバーター。(2 つの arduino 間の通信は正常に動作します)。

助けてください。

4

1 に答える 1

1

RS485 の例:

SN75176 IC を使用。

ここに画像の説明を入力

RE (pin 2) connect to ground(常に読むため)

Arduino制御のみDE PIN for writing data

しかし、PC副次的な問題:

  1. ブリッジされたDEピンはどこですか?(CTS,DTR,RTDサポートされている場合)
  2. あなたのフロー制御は何ですか?(関連 #1)
  3. ABピンに抵抗を接続しましたか?<+5V>----[560R]-----(A)----[120R]-----(B)------[560R]------<-5V>とても意地悪line end
  4. 信号をフィルタリングしましたかDE Pin 2(ノイズ用)

Aトリック:コンバーターSN75176のため、arduino側で使用しthis IC a RS232(UART) to (RS485)ます。

編集 : Modbus は、シリアル ( RTUASCII) で 2 つのタイプを取得しました。RS232/485の違いは気にしないでdifferent signal, same protocolください。

パケット タイプの例:

ASCII : :010300200004+CRC+FE(crc = パケット チェック コード、fe = 終了\x01\x03\x00\x20\x00\x04\x +CRC デリメータ) RTU : RTU について : すべてのバイトに 1.5 文字のスペースが必要で、デリメータはありませんstart and end

そしてModbus node type意味masterslave

お役に立てば幸いです。

于 2016-01-30T11:48:47.673 に答える