smarmengol / Modbus-Master-Slave-for-Arduino

Modbus Master-Slave library for Arduino
GNU Lesser General Public License v2.1
473 stars 328 forks source link

RS485 Half Duplex on SoftWareSerial #31

Closed HiTec-Tenshi closed 4 years ago

HiTec-Tenshi commented 6 years ago

Hi, Thank you for this library and the examples. I have a question.

include

include

define rxPin 2

define txPin 3

define mySerial Serial1

define ID 0 // 0 = Master > Slave ID

define Port 1

define RS485_pin 4

SoftwareSerial mySerial( rxPin, txPin )

master.begin( 38400, SERIAL_8E1 )

why this does not work?

and if you change

// Address, Serialport, Pin for RS485 (DE/RE) Modbus master(ID, Port, RS485_pin); // this is master and RS-232 or USB-FTDI

to

// Address, Pin for RS485 (DE/RE), Serialport Modbus master(ID, RS485_pin, Port); // this is master and RS-232 or USB-FTDI

you could use RS485 Half Duplex on SoftWareSerial easier.

Surbyte commented 5 years ago

You ddn´t understand how to inicialize the constructor. Modbus(uint8_t u8id, uint8_t u8serno, uint8_t u8txenpin);

When you casually invert the configuration it works but why? Because you have placed RS485_pin whose value is 4 as a port type and that is what corresponds to SoftwareSerial and u8txenpin is pin 1 same as TX of Serial. Your master config must be Modbus master(ID, 4, RS485_pin); // So simple!!