首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PC到Arduino RS-485通过转换器连接

PC到Arduino RS-485通过转换器连接
EN

Stack Overflow用户
提问于 2016-01-27 16:31:47
回答 1查看 5.5K关注 0票数 0

我试图在PC (Windows)和Arduino之间建立modbus RS-485连接.

在PC端,我使用USB到PC 485转换器,就像这个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一样。

Problem1:当我从PC发送字节到Arduino时,。什么都没发生。阿迪诺什么也没收到。在本例中,我将以下代码上传给Arduino:

代码语言:javascript
运行
复制
#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 485串口,并打开串口监视器发送一些数据。

因此,在Arduino侧串行监视器中,我只看到“-”行。即使当我试图发送一些在PC端串行监视器。

另一个问题是:

反之亦然。当我将一些字节从Arduino发送到PC时,我会收到一些奇怪的符号,而不是发送字节。

本例中的Arduino代码是:

代码语言:javascript
运行
复制
#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 side串行监视器中),我接收奇怪的符号而不是"3“符号。

=======

RS485转换器连接有双绞线A到A和B到B。RS485到TTL转换器连接到Arduino。(两个arduinos之间的交流很好)。

请帮帮忙。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-30 11:48:47

RS485的例子:

使用SN75176集成电路。

RE (pin 2) connect to ground (经常阅读)

只有DE PIN for writing data的Arduino控制

但是PC方面的问题:

  1. 桥接的DE引脚在哪里?(CTS,DTR,RTD (如果支持)
  2. 你的流量控制是什么?(相关#1)
  3. 你把电阻连接到AB引脚上了吗?<+5V>----[560R]-----(A)----[120R]-----(B)------[560R]------<-5V>这么刻薄的line end
  4. 你过滤了DE Pin 2信号(为了噪声)吗?

技巧:在arduino端使用SN75176,因为this IC a RS232(UART) to (RS485)转换器。

编辑: Modbus在串行上有2种类型(RTUASCII)。不要在意RS232 232/485的差异,因为different signal, same protocol

包类型示例:

:010300200004+CRC+FE(crc =数据包检查代码,fe=end标记) RTU : rtu上的\x01\x03\x00\x20\x00\x04\x +CRC:每个字节需要1.5个字符空间,没有start and end标记。

Modbus node type的意思是masterslave

我希望能帮上忙。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35042887

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档