serial port - PC to Arduino RS-485 connection via converters -


i'm trying make modbus rs-485 connection between pc (windows) , arduino.

on pc side use usb-to-rs485 converter 1 http://ru.aliexpress.com/item/usb-to-485-rs485-converter-adapter-support-windows-7-8-for-arduino/1577970568.html

on arduino side use ttl-to-rs-485 1 http://ru.aliexpress.com/item/5pcs-lot-max485-module-rs-485-ttl-to-rs485-module-for-arduino/32262338107.html

problem1: when send byte pc arduino. nothing happens. arduino not receive anything. in case upload arduino 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 show received data. open new instance of arduino ide, chose proper usb-to-rs485 com port , opens serial monitor send data.

so in arduino side serial monitor see "--" lines. when i'm trying send in pc side serial monitor.

the other problem is:

vice versa. when sending byte arduino pc receive odd symbols instead sent byte.

the arduino code in 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 master moment prepare 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 pc side (in arduino ides serial monitor) receive odd symbols instead "3" symbol.

=======

rs485 converters wired twisted pare a , b b. rs485 ttl converter connected arduino properly. (communication between 2 arduinos works fine).

please help.

example of rs485 :

using sn75176 ic.

enter image description here

re (pin 2) connect ground (for reading )

arduino control de pin writing data

but pc side problems:

  1. where bridged de pins ? (cts,dtr,rtd if supported)
  2. what flow control ? (related #1)
  3. did connect resistor a, b pin ?<+5v>----[560r]-----(a)----[120r]-----(b)------[560r]------<-5v> mean line end
  4. did filter de pin 2 signal (for noise)

a tricks : use sn75176 on arduino side because this ic rs232(uart) (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 , without start , end delimeter.

and modbus node type meaning master , slave.

i hope helpfull.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -