Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modbus RTU - Serial Direction Pin #62

Closed
gonzabrusco opened this issue Sep 4, 2020 · 6 comments
Closed

Modbus RTU - Serial Direction Pin #62

gonzabrusco opened this issue Sep 4, 2020 · 6 comments

Comments

@gonzabrusco
Copy link

Hello! First I want to congratulate you on such a great work you are doing.

Second I would like to make a request. When you are using Modbus RTU most of the times you use RS-485. And for using RS485 you need a transceiver.

The thing is, the transceivers need an extra line that tells them the dirección of the communication. When you are "hearing" for new data, the transceivers output must be in high-Z mode. So you must set this pin accordingly. When you want to send data, you must change the state of this pin. In the IC I'm using is HIGH to read, and LOW to write. But lots of other ICs use inverted logic.

What I would like you to implement is:

Add a method to tell MODBUS RTU that for writing or reading it must change the status of a pin. The pin number must be given on calling this method. Also, on calling this method you should also specify the logic (0= RECEIVING 1=SENDING or 1= RECEIVING 0=SENDING). You could make some define and specify them as NORMAL_LOGIC and INVERTED_LOGIC?

Finally, some transceivers have automatic direction recognition. So for those transceivers this pin is not needed. So if you don't call this method when creating de modbus rtu object should be Ok too.

That's all my friend. This would make your library really useful when using modbus RTU.

@gonzabrusco
Copy link
Author

For example: https://www.ti.com/product/ISO1430

The DE and RE pins normally are connected together and this way you control the direction of the communication with just one pin.

@gonzabrusco
Copy link
Author

gonzabrusco commented Sep 4, 2020

SORRY. I just saw you already implemented this.

bool begin(HardwareSerial* port, int16_t txPin=-1);

Could you add a way of changing the logic? Somethins the txPin is inverted logic (like in this IC TD331S485H-E) and you need to write 0 on txPin to send data and 1 to receive.

@emelianov emelianov added this to the 3.0.3 milestone Sep 4, 2020
@emelianov
Copy link
Owner

Hello,
It makes sense.

bool begin(SoftwareSerial* port, int16_t txPin=-1, bool direct=true);
bool begin(HardwareSerial* port, int16_t txPin=-1, bool direct=true);

Changes have pushed to master branch. For inverse logic use

mb.begin(&S, TX_PIN, false);

@gonzabrusco
Copy link
Author

Wow you are FAST. Thanks! I will try it during the weeking. Thanks again!!

@gonzabrusco
Copy link
Author

Ok. I tried modbusRTU as slave and as a master, using an inverted logic RS485 tranceiver. Everything works as expected. Thanks! Closing this now...

@fglaria
Copy link

fglaria commented Aug 11, 2021

SORRY. I just saw you already implemented this.

bool begin(HardwareSerial* port, int16_t txPin=-1);

Could you add a way of changing the logic? Somethins the txPin is inverted logic (like in this IC TD331S485H-E) and you need to write 0 on txPin to send data and 1 to receive.

Is there a way to add this to begin call with Stream?

bool ModbusRTU::begin(Stream* port) {
    _port = port;
    _t = 2;
    return true;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants